Class: SlackPomodoroTimer::Timer
- Inherits:
-
Object
- Object
- SlackPomodoroTimer::Timer
- Defined in:
- lib/slack_pomodoro_timer/timer.rb
Constant Summary collapse
- DONE =
:done
Instance Attribute Summary collapse
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#pomodoros ⇒ Object
Returns the value of attribute pomodoros.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Timer
constructor
Accepts options for pomodoros and a time interval in seconds.
-
#start(&block) ⇒ Object
Starts the timer calls the passed block for each pomodoro displays countdown until next interval.
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(={}) @pomodoros = [:pomodoros] @interval = [:interval] @total = [:pomodoros] end |
Instance Attribute Details
#interval ⇒ Object
Returns the value of attribute interval.
6 7 8 |
# File 'lib/slack_pomodoro_timer/timer.rb', line 6 def interval @interval end |
#pomodoros ⇒ Object
Returns the value of attribute pomodoros.
6 7 8 |
# File 'lib/slack_pomodoro_timer/timer.rb', line 6 def pomodoros @pomodoros end |
#total ⇒ Object (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 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 end end |