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?, #hash_like?

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.



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

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.



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

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.



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

def visit(value)
  value = @child.visit(value)
  if Array === value
    value.each_with_object([]) do |v, values|
      if Array === v
        values.concat(v)
      else
        values.push(v)
      end
    end
  else
    nil
  end
end