Module: MoneyAttribute::PluckAmount

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#pluck_amount(*attrs) ⇒ Array<Mint::Money>, Array<Array>

Plucks money-aware amounts for one or more attributes.

Parameters:

  • attrs (Array<Symbol>)

    one or more registered money attribute names

Returns:

  • (Array<Mint::Money>)

    for a single attribute

  • (Array<Array>)

    for multiple attributes, one row array per attribute

Raises:

  • (ArgumentError)

    if any attribute is not a registered money attribute



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

def pluck_amount(*attrs)
  raise ArgumentError, 'No attribute specified' if attrs.empty?

  specs = attrs.map { |attr| money_attribute_spec!(attr) }
  return pluck_single_amount(specs.first) if specs.length == 1

  raw = pluck(*specs.flat_map(&:columns))
  raw.map { |row| extract_money_row(row, specs) }
end