Class: ExRates

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

Constant Summary collapse

VERSION =
"0.1.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

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