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, query_options = {}) ⇒ Object
Constructor Details
#initialize(query_info) ⇒ HashParser
Returns a new instance of HashParser.
4 5 6 |
# File 'lib/search_cop/hash_parser.rb', line 4 def initialize(query_info) @query_info = query_info end |
Instance Attribute Details
#query_info ⇒ Object (readonly)
Returns the value of attribute query_info.
2 3 4 |
# File 'lib/search_cop/hash_parser.rb', line 2 def query_info @query_info end |
Instance Method Details
#parse(hash, query_options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/search_cop/hash_parser.rb', line 8 def parse(hash, = {}) default_operator = SearchCop::Helpers.sanitize_default_operator() 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(default_operator) end |