class JMESPath::Nodes::Index
Public Class Methods
new(key)
click to toggle source
# 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
Public Instance Methods
chain(other)
click to toggle source
# File lib/jmespath/nodes/field.rb, line 29 def chain(other) ChainedField.new([@key, *other.keys]) end
chains_with?(other)
click to toggle source
# File lib/jmespath/nodes/field.rb, line 25 def chains_with?(other) other.is_a?(Field) end
visit(value)
click to toggle source
# File lib/jmespath/nodes/field.rb, line 10 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
Protected Instance Methods
keys()
click to toggle source
# File lib/jmespath/nodes/field.rb, line 35 def keys [@key] end