Class: JMESPath::Nodes::Flatten Private

Inherits:
Node
  • Object
show all
Defined in:
lib/jmespath/nodes/flatten.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods inherited from Node

#chains_with?

Constructor Details

#initialize(child) ⇒ Flatten

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Flatten.



6
7
8
# File 'lib/jmespath/nodes/flatten.rb', line 6

def initialize(child)
  @child = child
end

Instance Method Details

#optimizeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
# File 'lib/jmespath/nodes/flatten.rb', line 23

def optimize
  self.class.new(@child.optimize)
end

#visit(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jmespath/nodes/flatten.rb', line 10

def visit(value)
  value = @child.visit(value)
  if value.respond_to?(:to_ary)
    value.to_ary.each_with_object([]) do |v, values|
      if v.respond_to?(:to_ary)
        values.concat(v.to_ary)
      else
        values.push(v)
      end
    end
  end
end