Class: Naplug::PerformanceData
- Inherits:
-
Object
- Object
- Naplug::PerformanceData
- Includes:
- Enumerable
- Defined in:
- lib/naplug/performancedata.rb
Constant Summary collapse
- FIELDS =
[:label, :value, :uom, :warn, :crit, :min, :max]
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #[](label) ⇒ Object
- #[]=(label, valuefields) ⇒ Object
-
#ancestors(options = { :mode => :tags, :separator => :/ }) ⇒ Array<Plugin>
Of parent plugins.
- #delete(label) ⇒ Object
- #each(&block) ⇒ Object
- #fields ⇒ Object
- #include?(label) ⇒ Boolean (also: #has_label?)
-
#initialize(plugin) ⇒ PerformanceData
constructor
A new instance of PerformanceData.
- #keys ⇒ Object (also: #labels)
-
#plugin ⇒ Plugin
Plugin performance data belongs to.
-
#to_a ⇒ Array<Hash<label,field_data>>
List of performance data label entries.
-
#to_str(label = nil) ⇒ Object
performance data format: ‘label=value;[warn];;[min];’.
Constructor Details
#initialize(plugin) ⇒ PerformanceData
Returns a new instance of PerformanceData.
13 14 15 16 17 |
# File 'lib/naplug/performancedata.rb', line 13 def initialize(plugin) @tag = plugin.tag @data = Hash.new @meta = OpenStruct.new :plugin => plugin, :ancestors => traverse_to_root(plugin) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/naplug/performancedata.rb', line 9 def data @data end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
9 10 11 |
# File 'lib/naplug/performancedata.rb', line 9 def @meta end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
9 10 11 |
# File 'lib/naplug/performancedata.rb', line 9 def tag @tag end |
Instance Method Details
#[](label) ⇒ Object
47 48 49 |
# File 'lib/naplug/performancedata.rb', line 47 def [](label) @data[curate_label(label)] end |
#[]=(label, valuefields) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/naplug/performancedata.rb', line 34 def []=(label,valuefields) value, fields = valuefields if validate_label label and validate_value value and validate_fields fields @data[curate_label(label)] = { :label => curate_label(label), :value => value }.merge fields else raise Naplug::Error, "invalid performance data label (#{label}), value (#{value}), field representation (#{fields.class}) or field (#{fields.keys.join(',')})" end end |
#ancestors(options = { :mode => :tags, :separator => :/ }) ⇒ Array<Plugin>
Returns of parent plugins.
75 76 77 78 |
# File 'lib/naplug/performancedata.rb', line 75 def ancestors( = { :mode => :tags, :separator => :/ }) [:separator] = :/ if [:separator].nil? [:mode].nil? ? @meta.ancestors : @meta.ancestors.map { |a| a.tag }.join([:separator].to_s) end |
#delete(label) ⇒ Object
51 52 53 |
# File 'lib/naplug/performancedata.rb', line 51 def delete(label) @data.delete(curate_label(label)) end |
#each(&block) ⇒ Object
43 44 45 |
# File 'lib/naplug/performancedata.rb', line 43 def each(&block) @data.values.each(&block) end |
#fields ⇒ Object
65 66 67 |
# File 'lib/naplug/performancedata.rb', line 65 def fields FIELDS end |
#include?(label) ⇒ Boolean Also known as: has_label?
55 56 57 |
# File 'lib/naplug/performancedata.rb', line 55 def include?(label) @data.has_key? curate_label(label) end |
#keys ⇒ Object Also known as: labels
60 61 62 |
# File 'lib/naplug/performancedata.rb', line 60 def keys @data.keys end |
#plugin ⇒ Plugin
Returns plugin performance data belongs to.
70 71 72 |
# File 'lib/naplug/performancedata.rb', line 70 def plugin @meta.plugin end |
#to_a ⇒ Array<Hash<label,field_data>>
List of performance data label entries
29 30 31 |
# File 'lib/naplug/performancedata.rb', line 29 def to_a @data.values end |
#to_str(label = nil) ⇒ Object
performance data format: ‘label=value;[warn];;[min];’
20 21 22 23 24 25 |
# File 'lib/naplug/performancedata.rb', line 20 def to_str(label = nil) label_ary = label.nil? ? labels : [curate_label(label)] label_ary.map do |l| '%s=%s%s;%s;%s;%s;%s' % FIELDS.map { |k| @data[l][k] } end.join(' ').strip end |