class Axiom::Aggregate::Sum

The sum of a sequence of numbers

Constants

DEFAULT

Public Class Methods

call(sum, value) click to toggle source

Return the sum for a sequence of numbers

@example

sum = Sum.call(sum, value)

@param [Numeric] sum

@param [Object] value

@return [Numeric]

@api public

# File lib/axiom/aggregate/sum.rb, line 23
def self.call(sum, value)
  return sum if value.nil?
  sum + value
end

Public Instance Methods

default() click to toggle source

Return the default sum

@example when the operand is a float

default = sum.default  # => 0.0

@example when the operand is a decimal

default = sum.default  # => BigDecimal('0.0')

@example when the operand is an integer

default = sum.default  # => 0

@return [Numeric]

@todo refactor once functions know their return types

@api public

Calls superclass method Axiom::Aggregate::default
# File lib/axiom/aggregate/sum.rb, line 44
def default
  if    type <= Types::Float   then super.to_f
  elsif type <= Types::Decimal then super.to_d
  else
    super
  end
end
type() click to toggle source

Return the type returned from call

@example

type = aggregate.type  # => Axiom::Types::Numeric

@return [Class<Types::Numeric>]

@api public

# File lib/axiom/aggregate/sum.rb, line 60
def type
  Attribute.infer_type(operand)
end