module Monee::Conversion

modularizing all the conversion related logic under one module

Public Instance Methods

convert_to(to_currency) click to toggle source

converts to a target currency

@param to_currency [String] @return [Money]

# 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) click to toggle source

convert to cents for a target currency

@param to_currency [String] @return [Numeric]

# 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