Class: AttrSearchableGrammar::Attributes::String

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

Direct Known Subclasses

Text

Instance Attribute Summary

Attributes inherited from Base

#attribute, #options

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

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

Dynamic Method Handling

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

Instance Method Details

#matches(value) ⇒ Object



128
129
130
# File 'lib/attr_searchable_grammar/attributes.rb', line 128

def matches(value)
  super matches_value(value)
end

#matches_value(value) ⇒ Object



122
123
124
125
126
# File 'lib/attr_searchable_grammar/attributes.rb', line 122

def matches_value(value)
  return value.gsub(/\*/, "%") if (options[:left_wildcard] != false && value.strip =~ /^[^*]+\*$|^\*[^*]+$/) || value.strip =~ /^[^*]+\*$/

  options[:left_wildcard] != false ? "%#{value}%" : "#{value}%"
end