Class: CopperEgg::MetricGroup::Metric
- Inherits:
-
Object
- Object
- CopperEgg::MetricGroup::Metric
- Defined in:
- lib/copperegg/metric_group.rb
Constant Summary collapse
- TYPES =
%w(ce_gauge ce_gauge_f ce_counter ce_counter_f)
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#label ⇒ Object
Returns the value of attribute label.
-
#name ⇒ Object
Returns the value of attribute name.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#type ⇒ Object
Returns the value of attribute type.
-
#unit ⇒ Object
Returns the value of attribute unit.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Metric
constructor
A new instance of Metric.
- #to_hash ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Metric
Returns a new instance of Metric.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/copperegg/metric_group.rb', line 65 def initialize(attributes={}) attributes.each do |name, value| if name.to_s == "position" @position = value elsif !respond_to?("#{name}=") next else send "#{name}=", value end end end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
63 64 65 |
# File 'lib/copperegg/metric_group.rb', line 63 def error @error end |
#label ⇒ Object
Returns the value of attribute label.
62 63 64 |
# File 'lib/copperegg/metric_group.rb', line 62 def label @label end |
#name ⇒ Object
Returns the value of attribute name.
62 63 64 |
# File 'lib/copperegg/metric_group.rb', line 62 def name @name end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
63 64 65 |
# File 'lib/copperegg/metric_group.rb', line 63 def position @position end |
#type ⇒ Object
Returns the value of attribute type.
62 63 64 |
# File 'lib/copperegg/metric_group.rb', line 62 def type @type end |
#unit ⇒ Object
Returns the value of attribute unit.
62 63 64 |
# File 'lib/copperegg/metric_group.rb', line 62 def unit @unit end |
Instance Method Details
#to_hash ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/copperegg/metric_group.rb', line 77 def to_hash self.instance_variables.reduce({}) do |memo, variable| if variable.to_s != "@error" value = instance_variable_get(variable) memo[variable.to_s.sub("@","")] = value end memo end end |
#valid? ⇒ Boolean
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/copperegg/metric_group.rb', line 87 def valid? valid = false @error = nil if self.name.nil? || self.name.to_s.strip.empty? @error = "Metric name cannot be blank." elsif self.type.nil? || self.type.to_s.strip.empty? @error = "Metric type must be defined." elsif !TYPES.include?(self.type) @error = "Invalid metric type #{self.type}." else valid = true remove_instance_variable(:@error) end valid end |