Class: Minder::PomodoroRunner
- Inherits:
-
Object
- Object
- Minder::PomodoroRunner
- Includes:
- Observable
- Defined in:
- lib/minder/pomodoro_runner.rb
Instance Attribute Summary collapse
-
#action_count ⇒ Object
readonly
Returns the value of attribute action_count.
-
#current_action ⇒ Object
readonly
Returns the value of attribute current_action.
-
#long_break_duration ⇒ Object
Returns the value of attribute long_break_duration.
-
#short_break_duration ⇒ Object
Returns the value of attribute short_break_duration.
-
#work_duration ⇒ Object
Returns the value of attribute work_duration.
Instance Method Summary collapse
- #advance_action ⇒ Object
- #break_duration ⇒ Object
- #continue ⇒ Object
-
#initialize(**options) ⇒ PomodoroRunner
constructor
A new instance of PomodoroRunner.
- #tick ⇒ Object
Constructor Details
#initialize(**options) ⇒ PomodoroRunner
Returns a new instance of PomodoroRunner.
18 19 20 21 22 23 24 |
# File 'lib/minder/pomodoro_runner.rb', line 18 def initialize(**) self.work_duration = .fetch(:work_duration) self.short_break_duration = .fetch(:short_break_duration) self.long_break_duration = .fetch(:long_break_duration) @action_count = 0 @current_action = IdlePeriod.new end |
Instance Attribute Details
#action_count ⇒ Object (readonly)
Returns the value of attribute action_count.
15 16 17 |
# File 'lib/minder/pomodoro_runner.rb', line 15 def action_count @action_count end |
#current_action ⇒ Object (readonly)
Returns the value of attribute current_action.
15 16 17 |
# File 'lib/minder/pomodoro_runner.rb', line 15 def current_action @current_action end |
#long_break_duration ⇒ Object
Returns the value of attribute long_break_duration.
11 12 13 |
# File 'lib/minder/pomodoro_runner.rb', line 11 def long_break_duration @long_break_duration end |
#short_break_duration ⇒ Object
Returns the value of attribute short_break_duration.
11 12 13 |
# File 'lib/minder/pomodoro_runner.rb', line 11 def short_break_duration @short_break_duration end |
#work_duration ⇒ Object
Returns the value of attribute work_duration.
11 12 13 |
# File 'lib/minder/pomodoro_runner.rb', line 11 def work_duration @work_duration end |
Instance Method Details
#advance_action ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/minder/pomodoro_runner.rb', line 48 def advance_action @action_count += 1 changed if action_count.odd? notify_observers(:started_work) @current_action = PomodoroPeriod.new(minutes: work_duration) else notify_observers(:started_break) @current_action = BreakPeriod.new(minutes: break_duration) end end |
#break_duration ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/minder/pomodoro_runner.rb', line 61 def break_duration if action_count % 8 == 0 long_break_duration else short_break_duration end end |
#continue ⇒ Object
41 42 43 44 45 46 |
# File 'lib/minder/pomodoro_runner.rb', line 41 def continue return unless current_action.elapsed? advance_action current_action.start! end |
#tick ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/minder/pomodoro_runner.rb', line 26 def tick return if !current_action.elapsed? || current_action.completed? old_action = current_action current_action.complete! @current_action = IdlePeriod.new changed if old_action.is_a?(PomodoroPeriod) notify_observers(:completed_work) elsif old_action.is_a?(BreakPeriod) notify_observers(:completed_break) end end |