Class: Elasticquery::Filters::Terms

Inherits:
Base
  • Object
show all
Defined in:
lib/elasticquery/filters/terms.rb

Constant Summary collapse

OPTIONS =
%i(_cache execution)

Instance Method Summary collapse

Methods inherited from Base

#dup_with, #invalid?, #to_not_hash

Constructor Details

#initialize(data = {}) ⇒ Terms

Returns a new instance of Terms.



9
10
11
12
# File 'lib/elasticquery/filters/terms.rb', line 9

def initialize(data = {})
  @options = data.slice *OPTIONS
  @conditions = data.except(*OPTIONS).delete_if{ |_, value| value.blank? }
end

Instance Method Details

#to_hashObject



18
19
20
# File 'lib/elasticquery/filters/terms.rb', line 18

def to_hash
  {terms: @conditions.merge(@options)}
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/elasticquery/filters/terms.rb', line 14

def valid?
  @conditions.keys.any?
end