Module: Monee::Conversion
- Included in:
- Money
- Defined in:
- lib/monee/conversion.rb
Overview
modularizing all the conversion related logic under one module
Instance Method Summary collapse
-
#convert_to(to_currency) ⇒ Money
converts to a target currency.
-
#convert_to_cents(to_currency) ⇒ Numeric
convert to cents for a target currency.
Instance Method Details
#convert_to(to_currency) ⇒ Money
converts to a target currency
8 9 10 11 |
# File 'lib/monee/conversion.rb', line 8 def convert_to(to_currency) amount = convert_to_cents(to_currency).to_amount klass.new(amount, to_currency) end |
#convert_to_cents(to_currency) ⇒ Numeric
convert to cents for a target currency
17 18 19 20 21 22 23 |
# File 'lib/monee/conversion.rb', line 17 def convert_to_cents(to_currency) if to_currency == currency cents else @currency.exchange(to_currency, cents) end end |