class JMESPath::Nodes::Field
Public Class Methods
Source
# File lib/jmespath/nodes/field.rb, line 6 def initialize(key) @key = key @key_sym = key.respond_to?(:to_sym) ? key.to_sym : nil end
Public Instance Methods
Source
# File lib/jmespath/nodes/field.rb, line 30 def chain(other) ChainedField.new([@key, *other.keys]) end
Source
# File lib/jmespath/nodes/field.rb, line 26 def chains_with?(other) other.is_a?(Field) end
Source
# File lib/jmespath/nodes/field.rb, line 11 def visit(value) if value.respond_to?(:to_ary) && @key.is_a?(Integer) value.to_ary[@key] elsif value.respond_to?(:to_hash) value = value.to_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