Class: Naplug::PerformanceData
- Inherits:
-
Object
- Object
- Naplug::PerformanceData
show all
- Defined in:
- lib/naplug/performancedata.rb
Defined Under Namespace
Classes: InvalidField, MissingLabel, ThatIsNoHash
Constant Summary
collapse
- FIELDS =
[:label, :value, :uom, :warn, :crit, :min, :max]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of PerformanceData.
13
14
15
16
|
# File 'lib/naplug/performancedata.rb', line 13
def initialize(tag)
@tag = tag
@data = Hash.new
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5
6
7
|
# File 'lib/naplug/performancedata.rb', line 5
def data
@data
end
|
#tag ⇒ Object
Returns the value of attribute tag.
5
6
7
|
# File 'lib/naplug/performancedata.rb', line 5
def tag
@tag
end
|
Instance Method Details
#[](label) ⇒ Object
Also known as:
fetch
33
34
35
|
# File 'lib/naplug/performancedata.rb', line 33
def [](label)
@data[label]
end
|
#[]=(label, value, args = {}) ⇒ Object
Also known as:
store
25
26
27
28
29
30
|
# File 'lib/naplug/performancedata.rb', line 25
def []=(label,value,args = {})
raise ThatIsNoHash, 'hash of fields is not a hash' unless args.is_a? Hash
args.keys.each { |field| raise InvalidField unless FIELDS.include? field }
raise MissingLabel, 'missing label' unless label
@data[label] = { :label => label, :value => value }.merge args
end
|
#delete(label) ⇒ Object
38
39
40
|
# File 'lib/naplug/performancedata.rb', line 38
def delete(label)
@data.delete(label)
end
|
#fields ⇒ Object
47
48
49
|
# File 'lib/naplug/performancedata.rb', line 47
def fields
FIELDS
end
|
#has_label?(label) ⇒ Boolean
Also known as:
include?
42
43
44
|
# File 'lib/naplug/performancedata.rb', line 42
def has_label?(label)
@data.has_key? label
end
|
#to_s(label = nil) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/naplug/performancedata.rb', line 18
def to_s(label = nil)
label_ary = label.nil? ? @data.keys : [label]
label_ary.map do |l|
'%s=%s%s;%s;%s;%s;%s' % FIELDS.map { |k| @data[l][k] }
end.join(' ').strip
end
|