Class: Qiita::Elasticsearch::Nodes::FilterableNode

Inherits:
Object
  • Object
show all
Defined in:
lib/qiita/elasticsearch/nodes/filterable_node.rb

Instance Method Summary collapse

Constructor Details

#initialize(tokens) ⇒ FilterableNode

Returns a new instance of FilterableNode.

Parameters:

  • tokens (Array<Qiita::Elasticsearch::Tokens>)


9
10
11
# File 'lib/qiita/elasticsearch/nodes/filterable_node.rb', line 9

def initialize(tokens)
  @tokens = tokens
end

Instance Method Details

#to_hashObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/qiita/elasticsearch/nodes/filterable_node.rb', line 13

def to_hash
  if filter_tokens.empty?
    QueryNode.new(not_filter_tokens).to_hash
  else
    {
      "filtered" => {
        "filter" => FilterNode.new(filter_tokens).to_hash,
        "query" => QueryNode.new(not_filter_tokens).to_hash,
      }.reject do |key, value|
        value.empty?
      end,
    }
  end
end