Class: Qiita::Elasticsearch::Nodes::OrSeparatableNode

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

Instance Method Summary collapse

Constructor Details

#initialize(tokens) ⇒ OrSeparatableNode

Returns a new instance of OrSeparatableNode.

Parameters:

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


9
10
11
# File 'lib/qiita/elasticsearch/nodes/or_separatable_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
27
28
# File 'lib/qiita/elasticsearch/nodes/or_separatable_node.rb', line 13

def to_hash
  case tokens_grouped_by_or_token.size
  when 0
    Nodes::AnyNode.new.to_hash
  when 1
    Nodes::FilterableNode.new(tokens_grouped_by_or_token.first).to_hash
  else
    {
      "bool" => {
        "should" => tokens_grouped_by_or_token.map do |tokens|
          Nodes::FilterableNode.new(tokens).to_hash
        end,
      },
    }
  end
end