Module: Monefy::Converter

Included in:
Monefy
Defined in:
lib/monefy/converter.rb

Overview

Encapsulate all the logic to convet currencies

Instance Method Summary collapse

Instance Method Details

#convert_to(to_currency) ⇒ Monefy

Converts a Monefy instance froma a currency to another.

Examples:

eur = Monefy.new(50, 'EUR')
eur.convert_to('USD') # => #<Monefy:0x... @amount=55, @currency="USD">

Parameters:

  • to_currency (String)

    currency to be converted to.

Returns:

  • (Monefy)

    new Monefy instance converted to another currency.



14
15
16
17
18
19
20
21
22
# File 'lib/monefy/converter.rb', line 14

def convert_to(to_currency)
  validate_currency(to_currency)

  calculated_amount = convert_currency(currency, amount, to_currency)
  create_new_instace(
    calculated_amount,
    to_currency
  )
end