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.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/copperegg/metric_group.rb', line 84 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.
82 83 84 |
# File 'lib/copperegg/metric_group.rb', line 82 def error @error end |
#label ⇒ Object
Returns the value of attribute label.
81 82 83 |
# File 'lib/copperegg/metric_group.rb', line 81 def label @label end |
#name ⇒ Object
Returns the value of attribute name.
81 82 83 |
# File 'lib/copperegg/metric_group.rb', line 81 def name @name end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
82 83 84 |
# File 'lib/copperegg/metric_group.rb', line 82 def position @position end |
#type ⇒ Object
Returns the value of attribute type.
81 82 83 |
# File 'lib/copperegg/metric_group.rb', line 81 def type @type end |
#unit ⇒ Object
Returns the value of attribute unit.
81 82 83 |
# File 'lib/copperegg/metric_group.rb', line 81 def unit @unit end |
Instance Method Details
#to_hash ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/copperegg/metric_group.rb', line 96 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
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/copperegg/metric_group.rb', line 106 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 |