Module: ECB::CurrencyConverter
- Defined in:
- lib/ecb/currency_converter.rb,
lib/ecb/currency_converter/version.rb
Overview
:nodoc:
Constant Summary collapse
- DAILY_URI =
'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'- CURRENCIES =
[ 'AUD', # Australian Dollar (A$) 'BGN', # Bulgarian Lev (BGN) 'BRL', # Brazilian Real (R$) 'CAD', # Canadian Dollar (CA$) 'CHF', # Swiss Franc (CHF) 'CNY', # Chinese Yuan (CN¥) 'CZK', # Czech Republic Koruna (CZK) 'DKK', # Danish Krone (DKK) 'EUR', # Euro (€) 'GBP', # British Pound Sterling (£) 'HKD', # Hong Kong Dollar (HK$) 'HRK', # Croatian Kuna (HRK) 'HUF', # Hungarian Forint (HUF) 'IDR', # Indonesian Rupiah (IDR) 'ILS', # Israeli New Sheqel (₪) 'INR', # Indian Rupee (Rs.) 'JPY', # Japanese Yen (¥) 'KRW', # South Korean Won (₩) 'LTL', # Lithuanian Litas (LTL) 'LVL', # Latvian Lats (LVL) 'MXN', # Mexican Peso (MX$) 'MYR', # Malaysian Ringgit (MYR) 'NOK', # Norwegian Krone (NOK) 'NZD', # New Zealand Dollar (NZ$) 'PHP', # Philippine Peso (Php) 'PLN', # Polish Zloty (PLN) 'RON', # Romanian Leu (RON) 'RUB', # Russian Ruble (RUB) 'SEK', # Swedish Krona (SEK) 'SGD', # Singapore Dollar (SGD) 'THB', # Thai Baht (฿) 'TRY', # Turkish Lira (TRY) 'USD', # US Dollar ($) 'ZAR', # South African Rand (ZAR) ]
- VERSION =
'0.1.0'
Class Method Summary collapse
-
.exchange(value, from, to) ⇒ Object
Converts the
valuebetweenfromandtocurrencies. -
.rate(from, to) ⇒ Object
Return the exchange rate between
fromandtocurrencies.
Class Method Details
.exchange(value, from, to) ⇒ Object
Converts the value between from and to currencies.
Example
ECB::CurrencyConverter.exchange(100, 'EUR', 'USD')
=> 133.73999999999998
ECB::CurrencyConverter.exchange(100, 'USD', 'EUR')
=> 74.77194556602363
65 66 67 |
# File 'lib/ecb/currency_converter.rb', line 65 def exchange(value, from, to) value * rate(from, to) end |
.rate(from, to) ⇒ Object
Return the exchange rate between from and to currencies.
Example
ECB::CurrencyConverter.rate('EUR', 'USD')
=> 1.3374
ECB::CurrencyConverter.rate('USD', 'EUR')
=> 0.7477194556602363
78 79 80 81 82 83 |
# File 'lib/ecb/currency_converter.rb', line 78 def rate(from, to) load_data! validate(from, to) 1.0 / @euro[from] * @euro[to] end |