Sha256: fb1f9d2a1f9be44033d9d668b3b0953ba91e7b47cd2b79954177d3d943fc1729

Contents?: true

Size: 1.08 KB

Versions: 12

Compression:

Stored size: 1.08 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]
  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

12 entries across 12 versions & 2 rubygems

Version Path
reel-eye-0.5.2.1 lib/eye/process/states_history.rb
reel-eye-0.5.2 lib/eye/process/states_history.rb
eye-0.5.2 lib/eye/process/states_history.rb
reel-eye-0.5.1 lib/eye/process/states_history.rb
eye-0.5.1 lib/eye/process/states_history.rb
reel-eye-0.5 lib/eye/process/states_history.rb
eye-0.5 lib/eye/process/states_history.rb
eye-0.4.2 lib/eye/process/states_history.rb
reel-eye-0.4.1 lib/eye/process/states_history.rb
eye-0.4.1 lib/eye/process/states_history.rb
reel-eye-0.4 lib/eye/process/states_history.rb
eye-0.4 lib/eye/process/states_history.rb