Class: Prb::Timer

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

Constant Summary collapse

WORKING =
1
PAUSED =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#completedObject (readonly)

Returns the value of attribute completed.



3
4
5
# File 'lib/prb/timer.rb', line 3

def completed
  @completed
end

#pausedObject (readonly)

Returns the value of attribute paused.



3
4
5
# File 'lib/prb/timer.rb', line 3

def paused
  @paused
end

#pomodorosObject (readonly)

Returns the value of attribute pomodoros.



3
4
5
# File 'lib/prb/timer.rb', line 3

def pomodoros
  @pomodoros
end

#secondsObject (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

Returns:

  • (Boolean)


42
43
44
# File 'lib/prb/timer.rb', line 42

def paused?
  @paused
end

#resetObject



36
37
38
39
40
# File 'lib/prb/timer.rb', line 36

def reset
  @paused = false
  @pomodoros = @opts.pomodoros
  set_timer(@opts.timer)
end

#resumeObject



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

def resume
  @paused = false
  set_timer(@opts.timer)
end

#tickObject



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