Fixed partial search formatter

This commit is contained in:
Sergei Tsoganov 2023-04-06 14:20:17 +03:00
parent 33175eea88
commit 4bf656f425

View file

@ -3,15 +3,23 @@ class PartialSearchFormatter
search_params = params.deep_dup search_params = params.deep_dup
search_params.each do |key, value| search_params.each do |key, value|
next unless key.include?('matches') && value.present? next unless should_format?(key, value)
if value =~ /\A\*.*\*\z/ search_params[key] = format_value(value)
search_params[key] = value.gsub(/\A\*|\*\z/, '')
else
search_params[key] = "%#{value}%"
end
end end
search_params search_params
end 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 end