Fix Rubocop warnings

This commit is contained in:
Hakan Ensari 2015-05-25 12:13:05 +01:00
parent 2bed405d0f
commit 4c72b6a139
5 changed files with 18 additions and 11 deletions

View File

@ -1,6 +1,7 @@
require 'logger'
require 'pathname'
# Encapsulates app configuration
module App
class << self
attr_reader :logger

View File

@ -21,7 +21,8 @@ helpers do
def snapshot
quotes = Snapshot.new(params).quote
if symbols = params.delete('symbols') || params.delete('currencies')
symbols = params.delete('symbols') || params.delete('currencies')
if symbols
symbols = symbols.split(',')
quotes[:rates].keep_if { |k, _| symbols.include?(k) }
end
@ -30,7 +31,9 @@ helpers do
end
def process_date
params[:date] = Date.new(params[:year].to_i, params[:month].to_i, params[:day].to_i)
params[:date] = Date.new(
params[:year].to_i, params[:month].to_i, params[:day].to_i
)
end
def halt_with_message(status, message)

View File

@ -1,3 +1,4 @@
# Wraps persisted currency data
class Currency < Sequel::Model
def self.last_date
order(:date).last.date

View File

@ -1,6 +1,7 @@
require 'virtus'
require 'currency'
# Quotes exchange rates on a specific date
class Snapshot
include Virtus.model
@ -8,13 +9,14 @@ class Snapshot
attribute :date, Date
def quote
self.date = if date
last_date = Currency.where("date <= '#{date}'").order(:date).last
raise ArgumentError.new('Date too old') unless last_date
last_date.date
else
Currency.last_date
end
self.date =
if date
last_date = Currency.where("date <= '#{date}'").order(:date).last
fail ArgumentError, 'Date too old' unless last_date
last_date.date
else
Currency.last_date
end
attributes.merge(rates: rebase(rates))
end
@ -30,7 +32,7 @@ class Snapshot
def rebase(rates)
if base.upcase! != 'EUR'
denominator = rates.update('EUR' => 1.0).delete(base)
raise ArgumentError.new('Invalid base') unless denominator
fail ArgumentError, 'Invalid base' unless denominator
rates.each do |iso_code, rate|
rates[iso_code] = round(rate / denominator)
end

View File

@ -41,7 +41,7 @@ describe 'the API' do
end
it 'allows cross-origin requests' do
get '/', {}, { 'HTTP_ORIGIN' => 'http://localhost' }
get '/', {}, 'HTTP_ORIGIN' => 'http://localhost'
assert_equal 'http://localhost', headers['Access-Control-Allow-Origin']
end
end