Class: AttrSearchable::HashParser

Inherits:
Object
  • Object
show all
Defined in:
lib/attr_searchable/hash_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ HashParser

Returns a new instance of HashParser.



3
4
5
# File 'lib/attr_searchable/hash_parser.rb', line 3

def initialize(model)
  @model = model
end

Instance Method Details

#parse(hash) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/attr_searchable/hash_parser.rb', line 7

def parse(hash)
  res = hash.collect do |key, value|
    case key
      when :and
        value.collect { |val| parse val }.inject(:and)
      when :or
        value.collect { |val| parse val }.inject(:or)
      when :not
        parse(value).not
      when :query
        AttrSearchable::Parser.parse value, @model
      else
        parse_attribute key, value
    end
  end

  res.inject :and
end