Class: Graphite::Tools::WhisperCalc

Inherits:
Object
  • Object
show all
Defined in:
lib/graphite/tools/whisper_calc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aggregation) ⇒ WhisperCalc

Returns a new instance of WhisperCalc.



10
11
12
# File 'lib/graphite/tools/whisper_calc.rb', line 10

def initialize(aggregation)
  @aggregation = aggregation
end

Instance Attribute Details

#aggregationObject (readonly)

Returns the value of attribute aggregation.



8
9
10
# File 'lib/graphite/tools/whisper_calc.rb', line 8

def aggregation
  @aggregation
end

Instance Method Details

#to_hObject



14
15
16
# File 'lib/graphite/tools/whisper_calc.rb', line 14

def to_h
  Hash[aggregation.split(',').map { |x| x.split(':').map(&:strip) }]
end

#to_iObject



18
19
20
21
22
# File 'lib/graphite/tools/whisper_calc.rb', line 18

def to_i
  to_h.inject(0) do |i, (k, v)|
    i + frequency_as_i(v) / frequency_as_i(k)
  end
end