Class: Mint::MoneyAttribute::Parser
- Inherits:
-
Object
- Object
- Mint::MoneyAttribute::Parser
- Defined in:
- lib/minting/money_attribute/parser.rb
Instance Method Summary collapse
- #call(amount, currency = @default_currency) ⇒ Object
-
#initialize(currency) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(currency) ⇒ Parser
Returns a new instance of Parser.
7 8 9 |
# File 'lib/minting/money_attribute/parser.rb', line 7 def initialize(currency) @default_currency = currency end |
Instance Method Details
#call(amount, currency = @default_currency) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/minting/money_attribute/parser.rb', line 11 def call(amount, currency = @default_currency) currency = Mint.assert_valid_currency!(currency) case amount when NilClass then nil when Mint::Money then amount when Numeric then Mint::Money.create(amount, currency) when String then Mint::Money.create(amount.to_r, currency) else if amount.respond_to? :to_money amount.to_money(currency) else Mint.parse(amount, currency) end end end |