mirror of
https://github.com/internetee/registry.git
synced 2025-08-27 11:33:32 +02:00
Fixed partial search formatter
This commit is contained in:
parent
33175eea88
commit
4bf656f425
1 changed files with 14 additions and 6 deletions
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue