Class: Minder::Timer
- Inherits:
-
Object
- Object
- Minder::Timer
- Defined in:
- lib/minder/timer.rb
Instance Attribute Summary collapse
-
#seconds ⇒ Object
Returns the value of attribute seconds.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Instance Method Summary collapse
- #completed? ⇒ Boolean
- #elapsed_time ⇒ Object
-
#initialize(seconds: DEFAULT_WORK_PERIOD) ⇒ Timer
constructor
A new instance of Timer.
- #start! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(seconds: DEFAULT_WORK_PERIOD) ⇒ Timer
Returns a new instance of Timer.
8 9 10 |
# File 'lib/minder/timer.rb', line 8 def initialize(seconds: DEFAULT_WORK_PERIOD) self.seconds = seconds end |
Instance Attribute Details
#seconds ⇒ Object
Returns the value of attribute seconds.
5 6 7 |
# File 'lib/minder/timer.rb', line 5 def seconds @seconds end |
#start_time ⇒ Object
Returns the value of attribute start_time.
5 6 7 |
# File 'lib/minder/timer.rb', line 5 def start_time @start_time end |
Instance Method Details
#completed? ⇒ Boolean
16 17 18 |
# File 'lib/minder/timer.rb', line 16 def completed? elapsed_time.to_i >= seconds end |
#elapsed_time ⇒ Object
20 21 22 23 24 |
# File 'lib/minder/timer.rb', line 20 def elapsed_time return 0 unless start_time (Time.now - start_time) end |
#start! ⇒ Object
12 13 14 |
# File 'lib/minder/timer.rb', line 12 def start! self.start_time = Time.now end |
#to_s ⇒ Object
26 27 28 29 |
# File 'lib/minder/timer.rb', line 26 def to_s "#{Minder.formatted_time(elapsed_time)} " \ "(out of #{Minder.formatted_time(seconds)})" end |