Class: CopperEgg::MetricGroup::Metric

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#errorObject (readonly)

Returns the value of attribute error.



82
83
84
# File 'lib/copperegg/metric_group.rb', line 82

def error
  @error
end

#labelObject

Returns the value of attribute label.



81
82
83
# File 'lib/copperegg/metric_group.rb', line 81

def label
  @label
end

#nameObject

Returns the value of attribute name.



81
82
83
# File 'lib/copperegg/metric_group.rb', line 81

def name
  @name
end

#positionObject (readonly)

Returns the value of attribute position.



82
83
84
# File 'lib/copperegg/metric_group.rb', line 82

def position
  @position
end

#typeObject

Returns the value of attribute type.



81
82
83
# File 'lib/copperegg/metric_group.rb', line 81

def type
  @type
end

#unitObject

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_hashObject



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

Returns:

  • (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