Work around holidays

This commit is contained in:
Hakan Ensari 2012-11-28 02:16:33 +00:00
parent a52fadf715
commit 4a8993cdfb
3 changed files with 18 additions and 10 deletions

View File

@ -7,25 +7,23 @@ set :root, File.expand_path('..', File.dirname(__FILE__))
helpers do
def redirect_to_api
if request.host =~ /^f/
redirect request.url.sub %r(://f), '://api.f'
if request.url.include? 'https://f'
redirect request.url.sub %r{//}, '//api.'
end
end
# Ugly as fuck.
def snapshot
symbols = params.delete('symbols') || params.delete('currencies')
quote = Snapshot
quotes = Snapshot
.new(params)
.quote
if symbols
if symbols = params.delete('symbols') || params.delete('currencies')
symbols = symbols.split ','
quote[:rates].keep_if { |k, v| symbols.include? k }
quotes[:rates].keep_if { |k, _| symbols.include? k }
end
quote
quotes
end
end

View File

@ -5,9 +5,20 @@ class Snapshot
include Virtus
attribute :base, String, default: 'EUR'
attribute :date, Date, default: proc { Currency.last_date }
attribute :date, Date
def quote
self.date =
if date
Currency
.where("date <= '#{date}'")
.order(:date)
.last
.date
else
Currency.last_date
end
attributes.merge rates: rebase(rates)
end

View File

@ -30,7 +30,6 @@ describe 'the application' do
end
it 'works around holidays' do
skip 'an "oh, wow" feature'
get '/2010-01-01'
json['rates'].wont_be :empty?
end