Class: SearchCop::HashParser
- Inherits:
-
Object
- Object
- SearchCop::HashParser
- Defined in:
- lib/search_cop/hash_parser.rb
Instance Attribute Summary collapse
-
#query_info ⇒ Object
readonly
Returns the value of attribute query_info.
Instance Method Summary collapse
-
#initialize(query_info) ⇒ HashParser
constructor
A new instance of HashParser.
- #parse(hash) ⇒ Object
Constructor Details
#initialize(query_info) ⇒ HashParser
5 6 7 |
# File 'lib/search_cop/hash_parser.rb', line 5 def initialize(query_info) @query_info = query_info end |
Instance Attribute Details
#query_info ⇒ Object (readonly)
Returns the value of attribute query_info.
3 4 5 |
# File 'lib/search_cop/hash_parser.rb', line 3 def query_info @query_info end |
Instance Method Details
#parse(hash) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/search_cop/hash_parser.rb', line 9 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 SearchCop::Parser.parse value, query_info else parse_attribute key, value end end res.inject :and end |