Class: ProgressBar::Timer
- Inherits:
-
Object
- Object
- ProgressBar::Timer
- Defined in:
- lib/ruby-progressbar/timer.rb
Instance Attribute Summary collapse
-
#started_at ⇒ Object
Returns the value of attribute started_at.
-
#stopped_at ⇒ Object
Returns the value of attribute stopped_at.
Instance Method Summary collapse
- #divide_seconds(seconds) ⇒ Object
- #elapsed_seconds ⇒ Object
- #elapsed_whole_seconds ⇒ Object
-
#initialize(options = {}) ⇒ Timer
constructor
A new instance of Timer.
- #pause ⇒ Object
- #reset ⇒ Object
- #reset? ⇒ Boolean
- #restart ⇒ Object
- #resume ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
- #stopped? ⇒ Boolean
Constructor Details
Instance Attribute Details
#started_at ⇒ Object
Returns the value of attribute started_at.
5 6 7 |
# File 'lib/ruby-progressbar/timer.rb', line 5 def started_at @started_at end |
#stopped_at ⇒ Object
Returns the value of attribute stopped_at.
5 6 7 |
# File 'lib/ruby-progressbar/timer.rb', line 5 def stopped_at @stopped_at end |
Instance Method Details
#divide_seconds(seconds) ⇒ Object
61 62 63 64 65 66 |
# 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 ⇒ Object
53 54 55 |
# File 'lib/ruby-progressbar/timer.rb', line 53 def elapsed_seconds ((stopped_at || time.now) - started_at) end |
#elapsed_whole_seconds ⇒ Object
57 58 59 |
# File 'lib/ruby-progressbar/timer.rb', line 57 def elapsed_whole_seconds elapsed_seconds.floor end |
#pause ⇒ Object
23 24 25 |
# File 'lib/ruby-progressbar/timer.rb', line 23 def pause stop end |
#reset ⇒ Object
39 40 41 42 |
# File 'lib/ruby-progressbar/timer.rb', line 39 def reset self.started_at = nil self.stopped_at = nil end |
#reset? ⇒ Boolean
44 45 46 |
# File 'lib/ruby-progressbar/timer.rb', line 44 def reset? !started_at end |
#restart ⇒ Object
48 49 50 51 |
# File 'lib/ruby-progressbar/timer.rb', line 48 def restart reset start end |
#resume ⇒ Object
27 28 29 |
# File 'lib/ruby-progressbar/timer.rb', line 27 def resume start end |
#start ⇒ Object
12 13 14 15 |
# 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? ⇒ Boolean
31 32 33 |
# File 'lib/ruby-progressbar/timer.rb', line 31 def started? started_at end |
#stop ⇒ Object
17 18 19 20 21 |
# File 'lib/ruby-progressbar/timer.rb', line 17 def stop return unless started? self.stopped_at = time.now end |
#stopped? ⇒ Boolean
35 36 37 |
# File 'lib/ruby-progressbar/timer.rb', line 35 def stopped? stopped_at end |