Class: TickTacker::Timer
- Inherits:
-
Object
- Object
- TickTacker::Timer
- Includes:
- Observable
- Defined in:
- lib/tick_tacker/timer.rb
Instance Attribute Summary collapse
-
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time.
-
#total_time ⇒ Object
readonly
Returns the value of attribute total_time.
Instance Method Summary collapse
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
- #notify ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #update(options = {}) ⇒ Object
- #update_time_elapsed(time) ⇒ Object
- #with(options) ⇒ Object
Constructor Details
#initialize ⇒ Timer
Returns a new instance of Timer.
10 11 12 |
# File 'lib/tick_tacker/timer.rb', line 10 def initialize with(:total_time => 25.minutes) end |
Instance Attribute Details
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time.
8 9 10 |
# File 'lib/tick_tacker/timer.rb', line 8 def elapsed_time @elapsed_time end |
#total_time ⇒ Object (readonly)
Returns the value of attribute total_time.
7 8 9 |
# File 'lib/tick_tacker/timer.rb', line 7 def total_time @total_time end |
Instance Method Details
#notify ⇒ Object
23 24 25 26 27 |
# File 'lib/tick_tacker/timer.rb', line 23 def notify time_remaining = total_time - elapsed_time = {:time_remaining => time_remaining} notify_observers() end |
#start ⇒ Object
45 46 47 48 49 |
# File 'lib/tick_tacker/timer.rb', line 45 def start @ticker.repeat do self.update end end |
#stop ⇒ Object
51 52 53 |
# File 'lib/tick_tacker/timer.rb', line 51 def stop @ticker.stop end |
#update(options = {}) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/tick_tacker/timer.rb', line 36 def update( = {}) @elapsed_time ||= 0 default = {:time_elapsed => @ticker.interval} config = default.merge() update_time_elapsed(config[:time_elapsed]) changed notify end |
#update_time_elapsed(time) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/tick_tacker/timer.rb', line 29 def update_time_elapsed(time) @elapsed_time += time if @elapsed_time >= @total_time @ticker.stop end end |