Class: Shattered::Timer::TimedEvent
- Defined in:
- lib/shattered_model/timed_event.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#time_remaining ⇒ Object
Returns the value of attribute time_remaining.
Instance Method Summary collapse
-
#initialize(context, seconds, options = {}, &block) ⇒ TimedEvent
constructor
A new instance of TimedEvent.
- #processed? ⇒ Boolean
- #reset ⇒ Object
-
#stop ⇒ Object
Stop the timer.
- #stopped? ⇒ Boolean
- #update(time_elapsed) ⇒ Object
Constructor Details
#initialize(context, seconds, options = {}, &block) ⇒ TimedEvent
Returns a new instance of TimedEvent.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/shattered_model/timed_event.rb', line 46 def initialize(context, seconds, ={}, &block) @context=context @event = block @options = if(seconds != :frame) @time_remaining = seconds @initial_time = @time_remaining else @time_remaining = 0 @initial_time = 0 end end |
Instance Attribute Details
#time_remaining ⇒ Object
Returns the value of attribute time_remaining.
45 46 47 |
# File 'lib/shattered_model/timed_event.rb', line 45 def time_remaining @time_remaining end |
Instance Method Details
#processed? ⇒ Boolean
66 67 68 |
# File 'lib/shattered_model/timed_event.rb', line 66 def processed? return @processed == true end |
#reset ⇒ Object
69 70 71 |
# File 'lib/shattered_model/timed_event.rb', line 69 def reset @time_remaining = @initial_time end |
#stop ⇒ Object
Stop the timer
73 74 75 |
# File 'lib/shattered_model/timed_event.rb', line 73 def stop @stopped = true end |
#stopped? ⇒ Boolean
76 77 78 |
# File 'lib/shattered_model/timed_event.rb', line 76 def stopped? !@stopped.nil? end |
#update(time_elapsed) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/shattered_model/timed_event.rb', line 58 def update(time_elapsed) return if processed? || stopped? @time_remaining -= time_elapsed if time_up? process_event @processed=true end end |