Class: Prb::TimerControl

Inherits:
Object
  • Object
show all
Defined in:
lib/prb/timer_control.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#timerObject (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_statusObject



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

#resetObject



28
29
30
# File 'lib/prb/timer_control.rb', line 28

def reset
  @timer.reset
end

#resumeObject



32
33
34
# File 'lib/prb/timer_control.rb', line 32

def resume
  @timer.resume
end

#startObject



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