class Proforma::Compiling::Counter

A counter is the actual underlying data structure for aggregation.

Attributes

count[R]
sum[R]

Public Class Methods

new() click to toggle source
# File lib/proforma/compiling/counter.rb, line 16
def initialize
  @count = 0
  @sum   = BigDecimal(0)
end

Public Instance Methods

add(value) click to toggle source
# File lib/proforma/compiling/counter.rb, line 21
def add(value)
  parsed_value = value.to_s.empty? ? 0 : BigDecimal(value.to_s)

  @count += 1
  @sum   += parsed_value

  self
end
ave() click to toggle source
# File lib/proforma/compiling/counter.rb, line 30
def ave
  return BigDecimal(0) if count.zero?

  sum / count
end