decrement()
click to toggle source
def decrement
self.progress -= 1 unless progress == 0
end
finish()
click to toggle source
def finish
self.progress = self.total
end
increment()
click to toggle source
def increment
self.progress += 1 unless progress == total
end
percentage_completed()
click to toggle source
def percentage_completed
return 100 if total == 0
self.progress * 100 / total
end
percentage_completed_with_precision()
click to toggle source
def percentage_completed_with_precision
format('%5.2f', (progress.to_f * 100.0 / total * 100.0).floor / 100.0)
end
progress=(new_progress)
click to toggle source
def progress=(new_progress)
validate_progress(new_progress)
@progress = new_progress
update_running_average
end
reset()
click to toggle source
def reset
start :at => self.starting_position
end
start(options = {})
click to toggle source
def start(options = {})
self.running_average = 0
self.progress = self.starting_position = options[:at] || self.progress
end
started?()
click to toggle source
def started?
!!self.starting_position
end
total=(new_total)
click to toggle source
def total=(new_total)
validate_total(new_total)
@total = new_total
end