Class: CbrRates
- Inherits:
-
Object
- Object
- CbrRates
- Defined in:
- lib/cbr_rates.rb,
lib/cbr_rates/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Attribute Summary collapse
-
#refreshed_at ⇒ Object
readonly
Returns the value of attribute refreshed_at.
Instance Method Summary collapse
- #exchange(money, currency_to) ⇒ Object
-
#initialize(date = Date.today) ⇒ CbrRates
constructor
A new instance of CbrRates.
- #rate(currency_code) ⇒ Object
Constructor Details
#initialize(date = Date.today) ⇒ CbrRates
Returns a new instance of CbrRates.
13 14 15 16 17 |
# File 'lib/cbr_rates.rb', line 13 def initialize(date = Date.today) @refreshed_at = Time.now parse!(date) end |
Instance Attribute Details
#refreshed_at ⇒ Object (readonly)
Returns the value of attribute refreshed_at.
11 12 13 |
# File 'lib/cbr_rates.rb', line 11 def refreshed_at @refreshed_at end |
Instance Method Details
#exchange(money, currency_to) ⇒ Object
23 24 25 26 27 |
# File 'lib/cbr_rates.rb', line 23 def exchange(money, currency_to) currency_from = money.currency.iso_code money.with_currency(currency_to) * rate(currency_from) / rate(currency_to) end |
#rate(currency_code) ⇒ Object
19 20 21 |
# File 'lib/cbr_rates.rb', line 19 def rate(currency_code) @rates[currency_code.upcase] end |