Class: Stretchy::Filters::BoolFilter

Inherits:
Base
  • Object
show all
Defined in:
lib/stretchy/filters/bool_filter.rb

Constant Summary

Constants included from Utils::Contract

Utils::Contract::ASSERTIONS, Utils::Contract::DECAY_FUNCTIONS, Utils::Contract::DISTANCE_FORMAT

Instance Method Summary collapse

Methods included from Utils::Contract

included, #require_one, #validate!

Constructor Details

#initialize(options = {}) ⇒ BoolFilter



11
12
13
14
15
16
17
# File 'lib/stretchy/filters/bool_filter.rb', line 11

def initialize(options = {})
  @must     = Array(options[:must])
  @must_not = Array(options[:must_not])
  @should   = Array(options[:should])
  validate!
  require_one(must: @must, must_not: @must_not, should: @should)
end

Instance Method Details

#to_searchObject



19
20
21
22
23
24
25
# File 'lib/stretchy/filters/bool_filter.rb', line 19

def to_search
  json = {}
  json[:must]     = @must.map(&:to_search)      if @must.any?
  json[:must_not] = @must_not.map(&:to_search)  if @must_not.any?
  json[:should]   = @should.map(&:to_search)    if @should.any?
  { bool: json }
end