Class: Prb::TimerControl
- Inherits:
-
Object
- Object
- Prb::TimerControl
- Defined in:
- lib/prb/timer_control.rb
Instance Attribute Summary collapse
-
#timer ⇒ Object
readonly
Returns the value of attribute timer.
Instance Method Summary collapse
-
#initialize(opts) ⇒ TimerControl
constructor
A new instance of TimerControl.
- #render_status ⇒ Object
- #reset ⇒ Object
- #resume ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(opts) ⇒ TimerControl
Returns a new instance of TimerControl.
5 6 7 8 |
# File 'lib/prb/timer_control.rb', line 5 def initialize(opts) @opts = opts @timer = Timer.new(@opts) end |
Instance Attribute Details
#timer ⇒ Object (readonly)
Returns the value of attribute timer.
3 4 5 |
# File 'lib/prb/timer_control.rb', line 3 def timer @timer end |
Instance Method Details
#render_status ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/prb/timer_control.rb', line 19 def render_status { running: !@timer.paused?, completed: @opts.pomodoros - @timer.pomodoros, remaining: @timer.pomodoros, time_remaining: @timer.seconds, }.to_json end |
#reset ⇒ Object
28 29 30 |
# File 'lib/prb/timer_control.rb', line 28 def reset @timer.reset end |
#resume ⇒ Object
32 33 34 |
# File 'lib/prb/timer_control.rb', line 32 def resume @timer.resume end |
#start ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/prb/timer_control.rb', line 10 def start Thread.new do loop do sleep 1 @timer.tick end end end |