Class: Pompom::Pomodoro
- Inherits:
-
Object
- Object
- Pompom::Pomodoro
- Defined in:
- lib/pompom.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#system_clock ⇒ Object
writeonly
Sets the attribute system_clock.
-
#time_remaining ⇒ Object
readonly
Returns the value of attribute time_remaining.
Instance Method Summary collapse
- #add_observer(object) ⇒ Object
- #finish! ⇒ Object
- #finished? ⇒ Boolean
- #finished_early? ⇒ Boolean
-
#initialize(time_remaining = 1500, message = nil) ⇒ Pomodoro
constructor
A new instance of Pomodoro.
- #tick ⇒ Object
Constructor Details
#initialize(time_remaining = 1500, message = nil) ⇒ Pomodoro
Returns a new instance of Pomodoro.
103 104 105 106 107 108 109 |
# File 'lib/pompom.rb', line 103 def initialize(time_remaining=1500, =nil) @time_remaining = time_remaining @message = @system_clock = Kernel @observers = [] @finished_early = true end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
100 101 102 |
# File 'lib/pompom.rb', line 100 def @message end |
#system_clock=(value) ⇒ Object (writeonly)
Sets the attribute system_clock
101 102 103 |
# File 'lib/pompom.rb', line 101 def system_clock=(value) @system_clock = value end |
#time_remaining ⇒ Object (readonly)
Returns the value of attribute time_remaining.
100 101 102 |
# File 'lib/pompom.rb', line 100 def time_remaining @time_remaining end |
Instance Method Details
#add_observer(object) ⇒ Object
111 112 113 |
# File 'lib/pompom.rb', line 111 def add_observer(object) @observers << object end |
#finish! ⇒ Object
122 123 124 125 |
# File 'lib/pompom.rb', line 122 def finish! @time_remaining = 0 notify_observers end |
#finished? ⇒ Boolean
131 132 133 |
# File 'lib/pompom.rb', line 131 def finished? @time_remaining < 1 end |
#finished_early? ⇒ Boolean
127 128 129 |
# File 'lib/pompom.rb', line 127 def finished_early? @finished_early end |
#tick ⇒ Object
115 116 117 118 119 120 |
# File 'lib/pompom.rb', line 115 def tick @system_clock.sleep 1 @time_remaining -= 1 @finished_early = false if @time_remaining == 0 notify_observers end |