mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-24 12:02:30 +01:00
Fix Rubocop warnings
This commit is contained in:
parent
2bed405d0f
commit
4c72b6a139
@ -1,6 +1,7 @@
|
||||
require 'logger'
|
||||
require 'pathname'
|
||||
|
||||
# Encapsulates app configuration
|
||||
module App
|
||||
class << self
|
||||
attr_reader :logger
|
||||
|
@ -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)
|
||||
|
@ -1,3 +1,4 @@
|
||||
# Wraps persisted currency data
|
||||
class Currency < Sequel::Model
|
||||
def self.last_date
|
||||
order(:date).last.date
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user