class PIM::Statistics::StatisticCalculator
Attributes
counts[R]
new_item[R]
old_item[R]
params[R]
Public Class Methods
new(old_item, new_item, params, &block)
click to toggle source
# File statistics.rb, line 68 def initialize old_item, new_item, params, &block @old_item = old_item @new_item = new_item @params = params @counts = {} if block.arity == 3 self.instance_exec(old_item, new_item, params, &block) elsif block.arity == 2 self.instance_exec(old_item, new_item, &block) else self.instance_exec(&block) end end
Public Instance Methods
count(key, value, *dimensions)
click to toggle source
# File statistics.rb, line 103 def count key, value, *dimensions # self[key, *dimensions] = value set(key, value, *dimensions) end
decr(key, *dimensions)
click to toggle source
# File statistics.rb, line 115 def decr key, *dimensions value = get(key, *dimensions) value -= 1 set(key, value, *dimensions) # self[key, *dimensions] -= 1 end
decr_all(keys, *dimensions)
click to toggle source
# File statistics.rb, line 128 def decr_all keys, *dimensions keys.each do |key| decr(key, *dimensions) end end
get(key, *dimensions)
click to toggle source
def []= key, *dimensions, value
@counts[key] ||= {} @counts[key][join_dimensions(*dimensions)] = value if is_not_empty?(value) and dimensions_set?(key, *dimensions)
end
# File statistics.rb, line 92 def get key, *dimensions return 0 if @counts[key].nil? or @counts[key].empty? @counts[key][join_dimensions(*dimensions)] || 0 end
incr(key, *dimensions)
click to toggle source
# File statistics.rb, line 108 def incr key, *dimensions value = get(key, *dimensions) value += 1 set(key, value, *dimensions) # self[key, *dimensions] += 1 end
incr_all(keys, *dimensions)
click to toggle source
# File statistics.rb, line 122 def incr_all keys, *dimensions keys.each do |key| incr(key, *dimensions) end end
set(key, value, *dimensions)
click to toggle source
# File statistics.rb, line 97 def set key, value, *dimensions return if is_empty?(value) or not dimensions_set?(key, *dimensions) @counts[key] ||= {} @counts[key][join_dimensions(*dimensions)] = value end