class ProgressBar::Timer
Attributes
started_at[RW]
stopped_at[RW]
time[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/ruby-progressbar/timer.rb, line 8 def initialize(options = {}) self.time = options[:time] || ::ProgressBar::Time.new end
Public Instance Methods
divide_seconds(seconds)
click to toggle source
# File lib/ruby-progressbar/timer.rb, line 61 def divide_seconds(seconds) hours, seconds = seconds.divmod(3600) minutes, seconds = seconds.divmod(60) [hours, minutes, seconds] end
elapsed_seconds()
click to toggle source
# File lib/ruby-progressbar/timer.rb, line 53 def elapsed_seconds ((stopped_at || time.now) - started_at) end
elapsed_whole_seconds()
click to toggle source
# File lib/ruby-progressbar/timer.rb, line 57 def elapsed_whole_seconds elapsed_seconds.floor end
pause()
click to toggle source
# File lib/ruby-progressbar/timer.rb, line 23 def pause stop end
reset()
click to toggle source
# File lib/ruby-progressbar/timer.rb, line 39 def reset self.started_at = nil self.stopped_at = nil end
reset?()
click to toggle source
# File lib/ruby-progressbar/timer.rb, line 44 def reset? !started_at end
restart()
click to toggle source
# File lib/ruby-progressbar/timer.rb, line 48 def restart reset start end
resume()
click to toggle source
# File lib/ruby-progressbar/timer.rb, line 27 def resume start end
start()
click to toggle source
# File lib/ruby-progressbar/timer.rb, line 12 def start self.started_at = stopped? ? time.now - (stopped_at - started_at) : time.now self.stopped_at = nil end
started?()
click to toggle source
# File lib/ruby-progressbar/timer.rb, line 31 def started? started_at end
stop()
click to toggle source
# File lib/ruby-progressbar/timer.rb, line 17 def stop return unless started? self.stopped_at = time.now end
stopped?()
click to toggle source
# File lib/ruby-progressbar/timer.rb, line 35 def stopped? stopped_at end