Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/nbrb_currency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class NbrbCurrency < Money::Bank::VariableExchange
NBRB_RATES_URL = 'http://nbrb.by/Services/XmlExRates.aspx'
CURRENCIES = %w(AUD BGN UAH DKK USD EUR PLN IRR ISK JPY CAD CNY KWD MDL NZD NOK RUB SGD KGS KZT TRY GBP CZK SEK CHF)

attr_reader :rates_updated_on

def update_rates(cache=nil)
exchange_rates(cache).each do |exchange_rate|
rate = exchange_rate.xpath("Rate").text
Expand Down Expand Up @@ -49,6 +51,7 @@ def exchange_with(from, to_currency)
def exchange_rates(cache=nil)
rates_source = !!cache ? cache : NBRB_RATES_URL
doc = Nokogiri::XML(open(rates_source))
@rates_updated_on = Date.strptime(doc.xpath('DailyExRates/@Date').text, '%m/%d/%Y')
doc.xpath('DailyExRates//Currency')
end

Expand Down
5 changes: 5 additions & 0 deletions spec/nbrb_currency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,9 @@
@bank.add_rate("BTC", "USD", 13.7603)
expect(@bank.exchange(100, "BTC", "USD").cents).to eq(138)
end

it "should tell on which date rates were updated" do
@bank.update_rates(@cache_path)
expect(@bank.rates_updated_on).to eq(Date.new(2015, 4, 8))
end
end