class Devilicious::CurrencyConverter
Public Class Methods
convert(amount, from, to)
click to toggle source
# File lib/devilicious/currency_converter.rb, line 7 def self.convert(amount, from, to) amount * rate(from, to) end
rate(from, to)
click to toggle source
# File lib/devilicious/currency_converter.rb, line 11 def self.rate from, to pair = [from, to].join if @rates[pair].nil? || @rates[pair].updated_at < Time.now - 10*60 Log.debug "Refreshing #{pair} rate..." rate = begin RateExchange.get_rate(from, to) rescue => exception Log.warn "Could not retrieve exchange rate from RateExchange: #{exception.inspect}" YahooExchange.get_rate(from, to) end @rates[pair] = OpenStruct.new( rate: rate, updated_at: Time.now ).freeze end @rates[pair].rate end