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 28 def chain(other) ChainedField.new([@key, *other.keys]) end
chains_with?(other)
click to toggle source
# File lib/jmespath/nodes/field.rb, line 24 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.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
Protected Instance Methods
keys()
click to toggle source
# File lib/jmespath/nodes/field.rb, line 34 def keys [@key] end