Class: Minder::PomodoroRunner
- Inherits:
-
Object
- Object
- Minder::PomodoroRunner
- Includes:
- Observable
- Defined in:
- lib/minder/pomodoro/pomodoro_runner.rb
Instance Attribute Summary collapse
-
#current_period ⇒ Object
readonly
Returns the value of attribute current_period.
-
#database ⇒ Object
Returns the value of attribute database.
-
#long_break_duration ⇒ Object
Returns the value of attribute long_break_duration.
-
#period_count ⇒ Object
readonly
Returns the value of attribute period_count.
-
#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_period ⇒ Object
- #break_duration ⇒ Object
- #complete_period(period) ⇒ Object
- #continue ⇒ Object
-
#initialize(**options) ⇒ PomodoroRunner
constructor
A new instance of PomodoroRunner.
- #periods ⇒ Object
- #pomodoros_today ⇒ Object
- #tick ⇒ Object
Constructor Details
#initialize(**options) ⇒ PomodoroRunner
Returns a new instance of PomodoroRunner.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/minder/pomodoro/pomodoro_runner.rb', line 19 def initialize(**) self.work_duration = .fetch(:work_duration) self.short_break_duration = .fetch(:short_break_duration) self.long_break_duration = .fetch(:long_break_duration) self.database = .fetch(:database) @period_count = 0 current_period = IdlePeriod.new current_period.start! database.add_period(current_period) @current_period = database.last_period end |
Instance Attribute Details
#current_period ⇒ Object (readonly)
Returns the value of attribute current_period.
16 17 18 |
# File 'lib/minder/pomodoro/pomodoro_runner.rb', line 16 def current_period @current_period end |
#database ⇒ Object
Returns the value of attribute database.
11 12 13 |
# File 'lib/minder/pomodoro/pomodoro_runner.rb', line 11 def database @database end |
#long_break_duration ⇒ Object
Returns the value of attribute long_break_duration.
11 12 13 |
# File 'lib/minder/pomodoro/pomodoro_runner.rb', line 11 def long_break_duration @long_break_duration end |
#period_count ⇒ Object (readonly)
Returns the value of attribute period_count.
16 17 18 |
# File 'lib/minder/pomodoro/pomodoro_runner.rb', line 16 def period_count @period_count end |
#short_break_duration ⇒ Object
Returns the value of attribute short_break_duration.
11 12 13 |
# File 'lib/minder/pomodoro/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/pomodoro_runner.rb', line 11 def work_duration @work_duration end |
Instance Method Details
#advance_period ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/minder/pomodoro/pomodoro_runner.rb', line 63 def advance_period @period_count += 1 changed if period_count.odd? notify_observers(:started_work) @current_period = WorkPeriod.new(duration_in_minutes: work_duration) else notify_observers(:started_break) @current_period = BreakPeriod.new(duration_in_minutes: break_duration) end end |
#break_duration ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/minder/pomodoro/pomodoro_runner.rb', line 76 def break_duration if period_count % 8 == 0 long_break_duration else short_break_duration end end |
#complete_period(period) ⇒ Object
58 59 60 61 |
# File 'lib/minder/pomodoro/pomodoro_runner.rb', line 58 def complete_period(period) database.complete_period(period) @pomodoros_today = nil end |
#continue ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/minder/pomodoro/pomodoro_runner.rb', line 46 def continue return unless current_period.elapsed? current_period.complete! complete_period(current_period) advance_period current_period.start! database.add_period(current_period) @current_period = database.last_period end |
#periods ⇒ Object
88 89 90 |
# File 'lib/minder/pomodoro/pomodoro_runner.rb', line 88 def periods database.periods end |
#pomodoros_today ⇒ Object
84 85 86 |
# File 'lib/minder/pomodoro/pomodoro_runner.rb', line 84 def pomodoros_today @pomodoros_today ||= database.pomodoros_today end |
#tick ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/minder/pomodoro/pomodoro_runner.rb', line 31 def tick return if !current_period.elapsed? || current_period.completed? old_period = current_period complete_period(old_period) @current_period = IdlePeriod.new changed if old_period.is_a?(WorkPeriod) notify_observers(:completed_work) elsif old_period.is_a?(BreakPeriod) notify_observers(:completed_break) end end |