Class: JMESPath::Nodes::Field Private

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

Direct Known Subclasses

ChainedField

Instance Method Summary collapse

Methods inherited from Node

#hash_like?, #optimize

Constructor Details

#initialize(key) ⇒ Field

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 Field


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

def initialize(key)
  @key = key
  @key_sym = key.respond_to?(:to_sym) ? key.to_sym : nil
end

Instance Method Details

#chain(other) ⇒ 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.


28
29
30
# File 'lib/jmespath/nodes/field.rb', line 28

def chain(other)
  ChainedField.new([@key, *other.keys])
end

#chains_with?(other) ⇒ Boolean

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:

  • (Boolean)

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

def chains_with?(other)
  other.is_a?(Field)
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
22
# File 'lib/jmespath/nodes/field.rb', line 10

def visit(value)
  if value.is_a?(Array) && @key.is_a?(Integer)
    value[@key]
  elsif value.is_a?(Hash)
    if !(v = value[@key]).nil?
      v
    elsif @key_sym && !(v = value[@key_sym]).nil?
      v
    end
  elsif value.is_a?(Struct) && value.respond_to?(@key)
    value[@key]
  end
end