Class: Eye::Process::StatesHistory
Instance Method Summary
collapse
Methods inherited from Utils::Tail
#<<, #initialize
Methods inherited from Array
#extract_options!
Instance Method Details
#all?(*seq) ⇒ Boolean
54
55
56
57
58
|
# File 'lib/eye/process/states_history.rb', line 54
def all?(*seq)
states.all? do |st|
seq.flatten.include?(st)
end
end
|
#any?(*seq) ⇒ Boolean
42
43
44
45
46
|
# File 'lib/eye/process/states_history.rb', line 42
def any?(*seq)
states.any? do |st|
seq.flatten.include?(st)
end
end
|
#end?(*seq) ⇒ Boolean
36
37
38
39
40
|
# File 'lib/eye/process/states_history.rb', line 36
def end?(*seq)
str = states * ','
substr = seq.flatten * ','
str.end_with?(substr)
end
|
#last_reason ⇒ Object
22
23
24
|
# File 'lib/eye/process/states_history.rb', line 22
def last_reason
last[:reason] rescue nil
end
|
#last_state ⇒ Object
18
19
20
|
# File 'lib/eye/process/states_history.rb', line 18
def last_state
last[:state]
end
|
#last_state_changed_at ⇒ Object
26
27
28
|
# File 'lib/eye/process/states_history.rb', line 26
def last_state_changed_at
Time.at(last[:at])
end
|
#noone?(*seq) ⇒ Boolean
48
49
50
51
52
|
# File 'lib/eye/process/states_history.rb', line 48
def noone?(*seq)
!states.all? do |st|
seq.flatten.include?(st)
end
end
|
#push(state, reason = nil, tm = Time.now) ⇒ Object
3
4
5
|
# File 'lib/eye/process/states_history.rb', line 3
def push(state, reason = nil, tm = Time.now)
super(state: state, at: tm.to_i, reason: reason)
end
|
#seq?(*seq) ⇒ Boolean
30
31
32
33
34
|
# File 'lib/eye/process/states_history.rb', line 30
def seq?(*seq)
str = states * ','
substr = seq.flatten * ','
str.include?(substr)
end
|
#state_count(state) ⇒ Object
60
61
62
63
64
|
# File 'lib/eye/process/states_history.rb', line 60
def state_count(state)
states.count do |st|
st == state
end
end
|
7
8
9
|
# File 'lib/eye/process/states_history.rb', line 7
def states
self.map{|c| c[:state] }
end
|
#states_for_period(period, from_time = nil) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/eye/process/states_history.rb', line 11
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
|