lib/money_oxr/rates_store.rb in money-oxr-0.2.0 vs lib/money_oxr/rates_store.rb in money-oxr-0.3.0
- old
+ new
@@ -4,12 +4,10 @@
require 'open-uri'
module MoneyOXR
class RatesStore < Money::RatesStore::Memory
- class UnsupportedCurrency < StandardError; end
-
attr_reader :app_id, :source, :cache_path, :last_updated_at, :max_age, :on_api_failure
def initialize(*)
super
@app_id = options[:app_id]
@@ -21,18 +19,18 @@
def get_rate(iso_from, iso_to)
load
super || begin
if iso_from == source
- raise UnsupportedCurrency.new(iso_to)
+ nil
elsif inverse_rate = super(iso_to, iso_from)
add_rate(iso_from, iso_to, 1 / inverse_rate)
elsif iso_to == source
- raise UnsupportedCurrency.new(iso_from)
+ nil
else
rate1 = get_rate(iso_from, source)
rate2 = get_rate(source, iso_to)
- add_rate(iso_from, iso_to, rate1 * rate2)
+ rate1 && rate2 && add_rate(iso_from, iso_to, rate1 * rate2)
end
end
end
def loaded?