Class: Prb::Timer
- Inherits:
-
Object
- Object
- Prb::Timer
- Defined in:
- lib/prb/timer.rb
Constant Summary collapse
- WORKING =
1
- PAUSED =
2
Instance Attribute Summary collapse
-
#completed ⇒ Object
readonly
Returns the value of attribute completed.
-
#paused ⇒ Object
readonly
Returns the value of attribute paused.
-
#pomodoros ⇒ Object
readonly
Returns the value of attribute pomodoros.
-
#seconds ⇒ Object
readonly
Returns the value of attribute seconds.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Timer
constructor
A new instance of Timer.
- #paused? ⇒ Boolean
- #reset ⇒ Object
- #resume ⇒ Object
- #tick ⇒ Object
Constructor Details
#initialize(opts) ⇒ Timer
Returns a new instance of Timer.
8 9 10 11 12 13 14 15 16 |
# File 'lib/prb/timer.rb', line 8 def initialize(opts) @opts = opts @paused = false @pomodoros = opts.pomodoros # set pomodoro timer set_timer(@opts.timer) end |
Instance Attribute Details
#completed ⇒ Object (readonly)
Returns the value of attribute completed.
3 4 5 |
# File 'lib/prb/timer.rb', line 3 def completed @completed end |
#paused ⇒ Object (readonly)
Returns the value of attribute paused.
3 4 5 |
# File 'lib/prb/timer.rb', line 3 def paused @paused end |
#pomodoros ⇒ Object (readonly)
Returns the value of attribute pomodoros.
3 4 5 |
# File 'lib/prb/timer.rb', line 3 def pomodoros @pomodoros end |
#seconds ⇒ Object (readonly)
Returns the value of attribute seconds.
3 4 5 |
# File 'lib/prb/timer.rb', line 3 def seconds @seconds end |
Instance Method Details
#paused? ⇒ Boolean
42 43 44 |
# File 'lib/prb/timer.rb', line 42 def paused? @paused end |
#reset ⇒ Object
36 37 38 39 40 |
# File 'lib/prb/timer.rb', line 36 def reset @paused = false @pomodoros = @opts.pomodoros set_timer(@opts.timer) end |
#resume ⇒ Object
31 32 33 34 |
# File 'lib/prb/timer.rb', line 31 def resume @paused = false set_timer(@opts.timer) end |
#tick ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/prb/timer.rb', line 18 def tick return if completed? or paused? if @seconds == 0 if @paused == false @pomodoros -= 1 @paused = true end else @seconds -= 1 end end |