Class: NbuRates

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

Constant Summary collapse

VERSION =
"0.1.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date = Date.today) ⇒ NbuRates

Returns a new instance of NbuRates.



15
16
17
18
19
# File 'lib/nbu_rates.rb', line 15

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.



13
14
15
# File 'lib/nbu_rates.rb', line 13

def refreshed_at
  @refreshed_at
end

Instance Method Details

#exchange(money, currency_to) ⇒ Object



25
26
27
28
29
# File 'lib/nbu_rates.rb', line 25

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



21
22
23
# File 'lib/nbu_rates.rb', line 21

def rate(currency_code)
  @rates[currency_code.upcase]
end