Class: MetricComputer

Inherits:
Object
  • Object
show all
Defined in:
lib/boxxspring/worker/metrics/metric_computer.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash, defaults) ⇒ MetricComputer

Returns a new instance of MetricComputer.



15
16
17
18
# File 'lib/boxxspring/worker/metrics/metric_computer.rb', line 15

def initialize( hash, defaults )
  @name, @value, @unit = hash.values
  @defaults = defaults
end

Instance Method Details

#nameObject



3
4
5
# File 'lib/boxxspring/worker/metrics/metric_computer.rb', line 3

def name
  @name ||= ""
end

#to_jsonObject



20
21
22
23
24
25
26
27
# File 'lib/boxxspring/worker/metrics/metric_computer.rb', line 20

def to_json
  {
    metric_name: name.to_s.capitalize,
    dimensions: normalize_dimensions_from_defaults( @defaults ),
    value: value.to_i,
    unit: unit.to_s.capitalize
  }
end

#unitObject



11
12
13
# File 'lib/boxxspring/worker/metrics/metric_computer.rb', line 11

def unit
  @unit ||= ""
end

#valueObject



7
8
9
# File 'lib/boxxspring/worker/metrics/metric_computer.rb', line 7

def value
  @value ||= 1
end