Class: SearchCopGrammar::Attributes::String

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

Direct Known Subclasses

Text

Instance Attribute Summary

Attributes inherited from Base

#attribute, #column_name, #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



176
177
178
# File 'lib/search_cop_grammar/attributes.rb', line 176

def matches(value)
  super matches_value(value)
end

#matches_value(value) ⇒ Object



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

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