class Ubea::CurrencyConverter::YahooExchange
Constants
- URL
Public Class Methods
get_csv(url)
click to toggle source
# File lib/ubea/currency_converter.rb, line 104 def self.get_csv(url) Retryable.retryable(tries: 3, sleep: 1) do csv = open(url).read csv.split(",") end end
get_rate(from, to)
click to toggle source
# File lib/ubea/currency_converter.rb, line 88 def self.get_rate(from, to) url = URL % [from, to] csv = get_csv(url) rate = BigDecimal.new(csv[1].to_s) if rate <= 1E-3 Log.warn "Cannot retrieve exchange rate for #{from}#{to}, not enough precision, using the opposite pair" url = URL % [to, from] csv = get_csv(url) rate = BigDecimal.new(1) / BigDecimal.new(csv[1].to_s) end rate end