mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-25 04:22:28 +01:00
e5815737c1
- bumped gems - rm bots - rm pry byebug - added rubocop-shopify and corrected generated warnings
40 lines
659 B
Ruby
40 lines
659 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Query
|
|
class << self
|
|
def build(params)
|
|
new(params).to_h
|
|
end
|
|
end
|
|
|
|
def initialize(params = {})
|
|
@params = params
|
|
end
|
|
|
|
def amount
|
|
return unless @params[:amount]
|
|
|
|
@params[:amount].to_f
|
|
end
|
|
|
|
def base
|
|
@params.values_at(:from, :base).compact.first&.upcase
|
|
end
|
|
|
|
def symbols
|
|
@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
|
|
{ amount:, base:, date:, symbols: }.compact
|
|
end
|
|
end
|