Sha256: 01b04650a1b4fec42fe6201f3436c7cc4afefcff92f9b3bc08f9fe687b621d40

Contents?: true

Size: 1.09 KB

Versions: 11

Compression:

Stored size: 1.09 KB

Contents

class Eye::Process::StatesHistory < Eye::Utils::Tail

  def push(state, reason = nil, tm = Time.now)
    super(state: state, at: tm.to_i, reason: reason)
  end

  def states
    self.map{|c| c[:state] }
  end

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

  def last_state
    last[:state]
  end

  def last_reason
    last[:reason] rescue nil
  end

  def last_state_changed_at
    Time.at(last[:at])
  end

  def seq?(*seq)
    str = states * ','
    substr = seq.flatten * ','
    str.include?(substr)
  end

  def end?(*seq)
    str = states * ','
    substr = seq.flatten * ','
    str.end_with?(substr)
  end

  def any?(*seq)
    states.any? do |st|
      seq.flatten.include?(st)
    end
  end

  def noone?(*seq)
    !states.all? do |st|
      seq.flatten.include?(st)
    end
  end

  def all?(*seq)
    states.all? do |st|
      seq.flatten.include?(st)
    end
  end

  def state_count(state)
    states.count do |st|
      st == state
    end
  end

end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
eye-0.6.4 lib/eye/process/states_history.rb
eye-0.6.3 lib/eye/process/states_history.rb
eye-0.6.2 lib/eye/process/states_history.rb
eye-0.6.2.pre lib/eye/process/states_history.rb
ace-eye-0.6.5 lib/eye/process/states_history.rb
ace-eye-0.6.4 lib/eye/process/states_history.rb
eye-0.6.1 lib/eye/process/states_history.rb
ace-eye-0.6.3 lib/eye/process/states_history.rb
ace-eye-0.6.2 lib/eye/process/states_history.rb
ace-eye-0.6.1 lib/eye/process/states_history.rb
eye-0.6 lib/eye/process/states_history.rb