mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-22 02:52:49 +01:00
parent
ddc0439340
commit
15e8d8b19b
@ -60,13 +60,12 @@ class Quote
|
||||
rates
|
||||
end
|
||||
|
||||
# I'm mimicking the apparent convention of the ECB here.
|
||||
def round_rate(rate)
|
||||
if rate > 100
|
||||
rate.round(2)
|
||||
elsif rate > 10
|
||||
rate.round(3)
|
||||
else
|
||||
rate.round(4)
|
||||
Float("%.#{5}g" % rate)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -33,19 +33,25 @@ describe Quote do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when given a non-euro base' do
|
||||
let(:quote) { Quote.new(base: 'USD') }
|
||||
describe 'when given a custom base' do
|
||||
let(:quote) { Quote.new(base: 'FOO') }
|
||||
|
||||
it 'quotes rates against that currency' do
|
||||
stub_rates 'USD' => 1.25 do |quote|
|
||||
rate = quote.rates['EUR']
|
||||
rate.must_equal 0.8
|
||||
stub_rates 'FOO' => 2 do |quote|
|
||||
quote.rates.keys.must_include 'EUR'
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not quote the base currency' do
|
||||
stub_rates 'USD' => 1.25 do |quote|
|
||||
quote.rates.keys.wont_include 'USD'
|
||||
stub_rates 'FOO' => 2 do |quote|
|
||||
quote.rates.keys.wont_include 'FOO'
|
||||
end
|
||||
end
|
||||
|
||||
it 'rounds to five significant digits' do
|
||||
stub_rates 'FOO' => 0.6995 do |quote|
|
||||
rate = quote.rates['EUR']
|
||||
rate.must_equal 1.4296
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user