Class: SlackPomodoroTimer::Timer

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

Constant Summary collapse

DONE =
:done

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Timer

Accepts options for pomodoros and a time interval in seconds



14
15
16
17
18
# File 'lib/slack_pomodoro_timer/timer.rb', line 14

def initialize(options={})
  @pomodoros = options[:pomodoros]
  @interval = options[:interval]
  @total = options[:pomodoros]
end

Instance Attribute Details

#intervalObject

Returns the value of attribute interval.



6
7
8
# File 'lib/slack_pomodoro_timer/timer.rb', line 6

def interval
  @interval
end

#pomodorosObject

Returns the value of attribute pomodoros.



6
7
8
# File 'lib/slack_pomodoro_timer/timer.rb', line 6

def pomodoros
  @pomodoros
end

#totalObject (readonly)

Returns the value of attribute total.



9
10
11
# File 'lib/slack_pomodoro_timer/timer.rb', line 9

def total
  @total
end

Instance Method Details

#start(&block) ⇒ Object

Starts the timer calls the passed block for each pomodoro displays countdown until next interval



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/slack_pomodoro_timer/timer.rb', line 24

def start(&block)
  puts start_message if @pomodoros == @total
  begin
    yield(current_pomodoro) if block_given?
    display_countdown
    @pomodoros -= 1
    if stop?
      stop(&block)
    else
      start(&block)
    end
  rescue SystemExit, Interrupt
    puts quit_message
  end
end