Class: Fulfil::Query
- Inherits:
-
Object
- Object
- Fulfil::Query
- Defined in:
- lib/fulfil/query.rb
Instance Method Summary collapse
- #exclude(*args) ⇒ Object
-
#initialize ⇒ Query
constructor
A new instance of Query.
- #query ⇒ Object
- #search(*args) ⇒ Object
Constructor Details
#initialize ⇒ Query
Returns a new instance of Query.
5 6 7 |
# File 'lib/fulfil/query.rb', line 5 def initialize @matchers = [] end |
Instance Method Details
#exclude(*args) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fulfil/query.rb', line 27 def exclude(*args) = args.first { |arg| arg.is_a?(Hash) && arg.key?(:options) }.fetch(:options, {}) terms = args.flat_map do |arg| arg.map do |field, value| next if value == build_exclude_term(field: field, value: value, options: ) end end if terms.length > 1 @matchers.push(['OR'].concat(terms)) else @matchers.concat(terms.first) end self end |
#query ⇒ Object
9 10 11 |
# File 'lib/fulfil/query.rb', line 9 def query @matchers end |
#search(*args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fulfil/query.rb', line 13 def search(*args) = args.first { |arg| arg.is_a?(Hash) && arg.key?(:options) }.fetch(:options, {}) args.each do |arg| arg.each do |field, value| next if value == @matchers.concat(build_search_term(field: field, value: value, options: )) end end self end |