Method: Eye::Process::StatesHistory#states_for_period

Defined in:
lib/eye/process/states_history.rb

#states_for_period(period, from_time = nil, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/eye/process/states_history.rb', line 11

def states_for_period(period, from_time = nil, &block)
  tm = Time.now - period
  tm = [tm, from_time].max if from_time
  tm = tm.to_f
  if block
    self.each { |s| yield(s) if s[:at] >= tm }
  else
    self.select { |s| s[:at] >= tm }.map { |c| c[:state] }
  end
end