frankfurter/lib/query.rb

38 lines
636 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class Query
2020-05-02 16:14:47 +02:00
def self.build(params)
new(params).to_h
end
def initialize(params = {})
@params = params
end
def amount
return unless @params[:amount]
2018-09-11 19:08:14 +02:00
@params[:amount].to_f
end
def base
@params.values_at(:from, :base).compact.first&.upcase
end
def symbols
2018-09-18 13:56:11 +02:00
@params.values_at(:to, :symbols).compact.first&.upcase&.split(',')
end
def date
if @params[:date]
Date.parse(@params[:date])
else
(Date.parse(@params[:start_date])..Date.parse(@params[:end_date]))
end
end
def to_h
2023-02-28 17:49:48 +01:00
{ amount:, base:, date:, symbols: }.compact
end
end