Class: SearchCopGrammar::Attributes::String

Inherits:
Base
  • Object
show all
Defined in:
lib/search_cop_grammar/attributes.rb

Direct Known Subclasses

Hstore, Json, Jsonb, Text

Instance Attribute Summary

Attributes inherited from Base

#attribute, #column_name, #field_names, #options, #table_alias

Instance Method Summary collapse

Methods inherited from Base

#compatible?, #fulltext?, #initialize, #map, #method_missing, #respond_to_missing?

Constructor Details

This class inherits a constructor from SearchCopGrammar::Attributes::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SearchCopGrammar::Attributes::Base

Instance Method Details

#matches(value) ⇒ Object



178
179
180
# File 'lib/search_cop_grammar/attributes.rb', line 178

def matches(value)
  super matches_value(value)
end

#matches_value(value) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/search_cop_grammar/attributes.rb', line 163

def matches_value(value)
  res = value.gsub(/[%_\\]/) { |char| "\\#{char}" }

  if value.strip =~ /^\*|\*$/
    res = res.gsub(/^\*/, "%") if options[:left_wildcard] != false
    res = res.gsub(/\*$/, "%") if options[:right_wildcard] != false

    return res
  end

  res = "%#{res}" if options[:left_wildcard] != false
  res = "#{res}%" if options[:right_wildcard] != false
  res
end