Class: Nordea::Bank
- Inherits:
-
Money::Bank::VariableExchange
- Object
- Money::Bank::VariableExchange
- Nordea::Bank
- Defined in:
- lib/nordea/bank.rb
Overview
Bank implementation for use with the Money gem.
Instance Method Summary collapse
-
#currencies(force = false) ⇒ Hash
Get the currency data from Nordea.
-
#exchange(cents, from_currency = "EUR", to_currency = "EUR") ⇒ Money
Exchange from one currency to another.
-
#exchange_rates ⇒ ExchangeRates
Initialize or use an existing Nordea::ExchangeRates object.
-
#exchange_with(from, to_currency) ⇒ Money
Exchanges the given
Money
object to a newMoney
object into_currency
. -
#initialize ⇒ Bank
constructor
A new instance of Bank.
-
#known_currencies ⇒ Array<String>
List currencies found in the Money gem and the Nordea currency data.
-
#money_currencies ⇒ Array<String>
List all currencies known to the money gem.
-
#update_rates ⇒ Hash
Get updated rates from the Nordea server.
Constructor Details
#initialize ⇒ Bank
Returns a new instance of Bank.
14 15 16 17 |
# File 'lib/nordea/bank.rb', line 14 def initialize super update_rates end |
Instance Method Details
#currencies(force = false) ⇒ Hash
Get the currency data from Nordea
77 78 79 |
# File 'lib/nordea/bank.rb', line 77 def currencies(force = false) exchange_rates.currencies(force) end |
#exchange(cents, from_currency = "EUR", to_currency = "EUR") ⇒ Money
Exchange from one currency to another
42 43 44 |
# File 'lib/nordea/bank.rb', line 42 def exchange(cents, from_currency = "EUR", to_currency = "EUR") exchange_with(Money.new(cents, from_currency), to_currency) end |
#exchange_rates ⇒ ExchangeRates
Initialize or use an existing Nordea::ExchangeRates object
69 70 71 |
# File 'lib/nordea/bank.rb', line 69 def exchange_rates @exchange_rates ||= Nordea::ExchangeRates.new end |
#exchange_with(from, to_currency) ⇒ Money
Exchanges the given Money
object to a new Money
object in to_currency
.
56 57 58 59 60 61 62 63 64 |
# File 'lib/nordea/bank.rb', line 56 def exchange_with(from, to_currency) rate = get_rate(from.currency, to_currency) unless rate from_base_rate = get_rate("EUR", from.currency) to_base_rate = get_rate("EUR", to_currency) rate = to_base_rate / from_base_rate end Money.new((from.cents * rate).round, to_currency) end |
#known_currencies ⇒ Array<String>
List currencies found in the Money gem and the Nordea currency data
91 92 93 |
# File 'lib/nordea/bank.rb', line 91 def known_currencies @known_currencies = money_currencies & exchange_rates.currencies.keys end |
#money_currencies ⇒ Array<String>
List all currencies known to the money gem
84 85 86 |
# File 'lib/nordea/bank.rb', line 84 def money_currencies Money::Currency.table.keys.map { |c| c.to_s.upcase } end |
#update_rates ⇒ Hash
Get updated rates from the Nordea server
Forces an update of the exchange rates
24 25 26 27 28 29 30 |
# File 'lib/nordea/bank.rb', line 24 def update_rates currencies(true).each_pair do |currency, data| rate = data[:middle_rate_for_commercial_transactions] add_rate("EUR", currency, rate) if known_currencies.include?(currency) end rates end |