Module: ProgressBar::Components::Timer

Included in:
ElapsedTimer, EstimatedTimer, Rate, Throttle
Defined in:
lib/ruby-progressbar/components/timer.rb

Constant Summary collapse

TIME_FORMAT =
'%02d:%02d:%02d'

Instance Method Summary collapse

Instance Method Details

#pauseObject



19
20
21
# File 'lib/ruby-progressbar/components/timer.rb', line 19

def pause
  stop
end

#resetObject



35
36
37
38
# File 'lib/ruby-progressbar/components/timer.rb', line 35

def reset
  @started_at = nil
  @stopped_at = nil
end

#resumeObject



23
24
25
# File 'lib/ruby-progressbar/components/timer.rb', line 23

def resume
  start
end

#startObject



8
9
10
11
# File 'lib/ruby-progressbar/components/timer.rb', line 8

def start
  @started_at = stopped? ? now - (@stopped_at - @started_at) : now
  @stopped_at = nil
end

#started?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ruby-progressbar/components/timer.rb', line 27

def started?
  !!@started_at
end

#stopObject



13
14
15
16
17
# File 'lib/ruby-progressbar/components/timer.rb', line 13

def stop
  return unless started?

  @stopped_at = now
end

#stopped?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/ruby-progressbar/components/timer.rb', line 31

def stopped?
  !!@stopped_at
end