Module: MoneyAttribute::SumAmount

Included in:
QueryMethods
Defined in:
lib/money_attribute/query/sum.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#sum_amount(attr) ⇒ Array<Mint::Money>

Sums money-aware amounts for a single attribute.

Parameters:

  • attr (Symbol)

    a registered money attribute name

Returns:

  • (Array<Mint::Money>)

    one Money per currency (or one for single-column attributes)

Raises:

  • (ArgumentError)

    if the attribute is not a registered money attribute



11
12
13
14
15
16
17
18
19
20
# File 'lib/money_attribute/query/sum.rb', line 11

def sum_amount(attr)
  raise ArgumentError, 'No attribute specified' if attr.nil?

  spec = money_attribute_spec!(attr)
  if spec.composite?
    resolve_composite_sum(spec)
  else
    resolve_single_sum(spec)
  end
end