Class: JMESPath::Nodes::ChainedField Private

Inherits:
Field
  • Object
show all
Defined in:
lib/jmespath/nodes/field.rb

Overview

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.

API:

  • private

Instance Method Summary collapse

Methods inherited from Field

#chain, #chains_with?

Methods inherited from Node

#chains_with?, #hash_like?, #optimize

Constructor Details

#initialize(keys) ⇒ ChainedField

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

API:

  • private



37
38
39
40
41
42
43
44
# File 'lib/jmespath/nodes/field.rb', line 37

def initialize(keys)
  @keys = keys
  @key_syms = keys.each_with_object({}) do |k, syms|
    if k.respond_to?(:to_sym)
      syms[k] = k.to_sym
    end
  end
end

Instance Method Details

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

API:

  • private



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

def visit(value)
  @keys.reduce(value) do |value, key|
    if value.is_a?(Array) && key.is_a?(Integer)
      value[key]
    elsif value.is_a?(Hash)
      if !(v = value[key]).nil?
        v
      elsif (sym = @key_syms[key]) && !(v = value[sym]).nil?
        v
      end
    elsif value.is_a?(Struct) && value.respond_to?(key)
      value[key]
    end
  end
end