Class: MoneyAttribute::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/money_attribute/converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(currency = MoneyAttribute.default_currency) ⇒ Converter

Returns a new instance of Converter.



5
6
7
# File 'lib/money_attribute/converter.rb', line 5

def initialize(currency = MoneyAttribute.default_currency)
  @default_currency = currency
end

Instance Method Details

#parse(amount, currency = @default_currency) ⇒ Object Also known as: call



9
10
11
12
13
14
15
# File 'lib/money_attribute/converter.rb', line 9

def parse(amount, currency = @default_currency)
  case amount
  when Mint::Money, NilClass then amount
  when Numeric               then Mint::Money.from(amount, currency)
  else                            Mint.parse(amount, currency)
  end
end