Class: LogfileInterval::Aggregator::Delta

Inherits:
Base
  • Object
show all
Defined in:
lib/logfile_interval/aggregator/delta.rb

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#value, #values

Methods included from Registrar

#aggregator_classes, #all, #exist?, #inherited, #klass, #register_aggregator

Constructor Details

#initialize(options = {}) ⇒ Delta

Returns a new instance of Delta.



4
5
6
7
# File 'lib/logfile_interval/aggregator/delta.rb', line 4

def initialize(options = {})
  @previous = Util::Counter.new
  super
end

Instance Method Details

#add(value, group_by_value = nil) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/logfile_interval/aggregator/delta.rb', line 9

def add(value, group_by_value = nil)
  if @previous.has_key?(key(group_by_value))
    @val.add(key(group_by_value), value - @previous[key(group_by_value)])
    @size.increment(key(group_by_value))
  end
  @previous.set(key(group_by_value), value)
end

#val(k) ⇒ Object



17
18
19
# File 'lib/logfile_interval/aggregator/delta.rb', line 17

def val(k)
  average(k)
end