Class: CbrRates

Inherits:
Object
  • Object
show all
Defined in:
lib/cbr_rates.rb,
lib/cbr_rates/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

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_atObject (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