Class: MoneyAttribute::Converter
- Inherits:
-
Object
- Object
- MoneyAttribute::Converter
- Defined in:
- lib/money_attribute/converter.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(currency = MoneyAttribute.default_currency) ⇒ Converter
constructor
A new instance of Converter.
- #parse(amount) ⇒ Object (also: #call)
Constructor Details
#initialize(currency = MoneyAttribute.default_currency) ⇒ Converter
Returns a new instance of Converter.
6 7 8 |
# File 'lib/money_attribute/converter.rb', line 6 def initialize(currency = MoneyAttribute.default_currency) @default_currency = currency end |
Instance Method Details
#parse(amount) ⇒ Object Also known as: call
10 11 12 13 14 15 16 17 |
# File 'lib/money_attribute/converter.rb', line 10 def parse(amount) case amount when Money, NilClass then amount when Numeric then Money.from(amount, @default_currency) when String then Money.parse(amount, @default_currency) else raise ArgumentError, "Cannot convert #{amount.inspect} (#{amount.class}) to Money" end end |