Class: Zyps::ElapsedTimeCondition

Inherits:
Condition
  • Object
show all
Defined in:
lib/zyps/conditions.rb

Overview

True if the given interval has elapsed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval = 1.0) ⇒ 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

#intervalObject

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