Class: CurrencyExchange::Exchangers::OpenExchange

Inherits:
Object
  • Object
show all
Defined in:
lib/currency_exchange/exchangers/open_exchange.rb

Constant Summary collapse

LATEST_EXCHANGE_URL =
"http://openexchangerates.org/latest.json"

Instance Method Summary collapse

Constructor Details

#initializeOpenExchange

Returns a new instance of OpenExchange.



6
7
8
# File 'lib/currency_exchange/exchangers/open_exchange.rb', line 6

def initialize
  @transporter = CurrencyExchange::Transporters::ExchangeTransporter.load_instance(:json)
end

Instance Method Details

#convert(number, from, to) ⇒ Object



10
11
12
# File 'lib/currency_exchange/exchangers/open_exchange.rb', line 10

def convert(number, from, to)
  number * rates[to.upcase] * ( 1 / rates[from.upcase] ) if rates[to.upcase] && rates[from.upcase]
end