Module: AttrSearchable::Parser

Defined in:
lib/attr_searchable.rb

Class Method Summary collapse

Class Method Details

.parse(query, model) ⇒ Object



21
22
23
# File 'lib/attr_searchable.rb', line 21

def self.parse(query, model)
  query.is_a?(Hash) ? parse_hash(query, model) : parse_string(query, model)
end

.parse_hash(hash, model) ⇒ Object



25
26
27
# File 'lib/attr_searchable.rb', line 25

def self.parse_hash(hash, model)
  AttrSearchable::HashParser.new(model).parse(hash) || raise(ParseError)
end

.parse_string(string, model) ⇒ Object



29
30
31
32
33
# File 'lib/attr_searchable.rb', line 29

def self.parse_string(string, model)
  node = AttrSearchableGrammarParser.new.parse(string) || raise(ParseError)
  node.model = model
  node.evaluate
end