class Copperegg::Revealmetrics::MetricGroup::Metric

Constants

TYPES

Attributes

error[R]
label[RW]
name[RW]
position[R]
type[RW]
unit[RW]

Public Class Methods

new(attributes={}) click to toggle source
# File lib/copperegg/revealmetrics/metric_group.rb, line 86
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

Public Instance Methods

to_hash() click to toggle source
# File lib/copperegg/revealmetrics/metric_group.rb, line 98
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?() click to toggle source
# File lib/copperegg/revealmetrics/metric_group.rb, line 108
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