2018-03-08 02:05:19 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Query
|
|
|
|
def initialize(params = {})
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def amount
|
2018-07-05 21:19:37 +02:00
|
|
|
return unless @params[:amount]
|
|
|
|
@params[:amount].to_f
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def base
|
2018-07-05 21:19:37 +02:00
|
|
|
@params.values_at(:from, :base).compact.first&.upcase
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def symbols
|
2018-07-05 21:19:37 +02:00
|
|
|
@params.values_at(:to, :symbols).compact.first&.split(',')
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def date
|
2018-07-05 21:19:37 +02:00
|
|
|
if @params[:date]
|
|
|
|
Date.parse(@params[:date])
|
|
|
|
else
|
|
|
|
(Date.parse(@params[:start_date])..Date.parse(@params[:end_date]))
|
|
|
|
end
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_h
|
|
|
|
{ amount: amount, base: base, date: date, symbols: symbols }.compact
|
|
|
|
end
|
|
|
|
end
|