Class: JMESPath::Nodes::Chain Private

Inherits:
Object
  • Object
show all
Defined in:
lib/jmespath/nodes/subexpression.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

Constructor Details

#initialize(children) ⇒ Chain

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 Chain.



38
39
40
# File 'lib/jmespath/nodes/subexpression.rb', line 38

def initialize(children)
  @children = children
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.



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/jmespath/nodes/subexpression.rb', line 48

def optimize
  children = @children.map(&:optimize)
  index = 0
  while index < children.size - 1
    if children[index].chains_with?(children[index + 1])
      children[index] = children[index].chain(children[index + 1])
      children.delete_at(index + 1)
    else
      index += 1
    end
  end
  Chain.new(children)
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.



42
43
44
45
46
# File 'lib/jmespath/nodes/subexpression.rb', line 42

def visit(value)
  @children.reduce(value) do |v, child|
    child.visit(v)
  end
end