Class: Zyps::ElapsedTimeCondition
- Inherits:
-
Condition
- Object
- Condition
- Zyps::ElapsedTimeCondition
- Defined in:
- lib/zyps/conditions.rb
Overview
True if the given interval has elapsed.
Instance Attribute Summary collapse
-
#interval ⇒ Object
The number of seconds that must elapse before the condition is true.
Instance Method Summary collapse
-
#initialize(interval = 1.0) ⇒ ElapsedTimeCondition
constructor
A new instance of ElapsedTimeCondition.
-
#select(actor, targets) ⇒ Object
Returns the array of targets if the interval has elapsed.
Constructor Details
#initialize(interval = 1.0) ⇒ ElapsedTimeCondition
Returns a new instance of ElapsedTimeCondition.
112 113 114 115 116 |
# File 'lib/zyps/conditions.rb', line 112 def initialize(interval = 1.0) self.interval = interval @clock = Clock.new @elapsed_time = 0 end |
Instance Attribute Details
#interval ⇒ Object
The number of seconds that must elapse before the condition is true.
111 112 113 |
# File 'lib/zyps/conditions.rb', line 111 def interval @interval end |
Instance Method Details
#select(actor, targets) ⇒ Object
Returns the array of targets if the interval has elapsed.
118 119 120 121 122 123 124 125 126 |
# File 'lib/zyps/conditions.rb', line 118 def select(actor, targets) @elapsed_time += @clock.elapsed_time if @elapsed_time >= interval @elapsed_time = 0 return targets else return [] end end |