Class: Monies::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/monies/format.rb

Direct Known Subclasses

EN, EU

Defined Under Namespace

Classes: EN, EU

Instance Method Summary collapse

Instance Method Details

#call(instance, symbol: false, code: false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/monies/format.rb', line 4

def call(instance, symbol: false, code: false)
  if symbol && code
    raise ArgumentError, "can't format with both symbol and code keyword arguments"
  end

  digits = Monies::Digits.dump(instance, scale: scale, zero: zero, separator: separator, thousands_separator: thousands_separator)

  if symbol
    Monies.symbols.fetch_key(instance.currency) + digits
  elsif code
    "#{digits} #{instance.currency}"
  else
    digits
  end
end