Class: Fulfil::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/fulfil/query.rb

Instance Method Summary collapse

Constructor Details

#initializeQuery

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)
  options = 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 == options

      build_exclude_term(field: field, value: value, options: options)
    end
  end

  if terms.length > 1
    @matchers.push(['OR'].concat(terms))
  else
    @matchers.concat(terms.first)
  end

  self
end

#queryObject



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)
  options = args.first { |arg| arg.is_a?(Hash) && arg.key?(:options) }.fetch(:options, {})

  args.each do |arg|
    arg.each do |field, value|
      next if value == options

      @matchers.concat(build_search_term(field: field, value: value, options: options))
    end
  end

  self
end