mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 21:16:12 +02:00
25 lines
489 B
Ruby
25 lines
489 B
Ruby
class PartialSearchFormatter
|
|
def self.format(params)
|
|
search_params = params.deep_dup
|
|
|
|
search_params.each do |key, value|
|
|
next unless should_format?(key, value)
|
|
|
|
search_params[key] = format_value(value)
|
|
end
|
|
|
|
search_params
|
|
end
|
|
|
|
def self.should_format?(key, value)
|
|
key.include?('matches') && value.present?
|
|
end
|
|
|
|
def self.format_value(value)
|
|
if value =~ /\A\*.*\*\z/
|
|
value.gsub(/\A\*|\*\z/, '')
|
|
else
|
|
"%#{value}%"
|
|
end
|
|
end
|
|
end
|