Class: Stretchy::Filters::BoolFilter

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

Instance Method Summary collapse

Methods included from Utils::Validation

#errors, included, #require_one!, #require_only_one!, #valid?, #validate!, #validator

Constructor Details

#initialize(options = {}) ⇒ BoolFilter

Returns a new instance of BoolFilter.



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

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

Instance Method Details

#to_searchObject



25
26
27
28
29
30
31
# File 'lib/stretchy/filters/bool_filter.rb', line 25

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