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, Index

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
9
# File 'lib/jmespath/nodes/field.rb', line 5

def initialize(key)
  @key = key
  @keys = [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.



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

def chain(other)
  ChainedField.new([*keys, *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)


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

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.



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

def visit(value)
  if 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