Class: ExRates
- Inherits:
-
Object
- Object
- ExRates
- Defined in:
- lib/exrates.rb,
lib/exrates/version.rb
Constant Summary collapse
- VERSION =
"0.1.2"
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) ⇒ ExRates
constructor
A new instance of ExRates.
- #rate(currency_code) ⇒ Object
Constructor Details
#initialize(date = Date.today) ⇒ ExRates
Returns a new instance of ExRates.
12 13 14 15 16 |
# File 'lib/exrates.rb', line 12 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.
10 11 12 |
# File 'lib/exrates.rb', line 10 def refreshed_at @refreshed_at end |
Instance Method Details
#exchange(money, currency_to) ⇒ Object
22 23 24 25 26 |
# File 'lib/exrates.rb', line 22 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
18 19 20 |
# File 'lib/exrates.rb', line 18 def rate(currency_code) @rates[currency_code.upcase] end |