Class: Neo4j::Driver::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4j/driver/record.rb

Overview

Represents a single record (row) in a result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keys, values) ⇒ Record

Returns a new instance of Record.



7
8
9
10
11
12
13
14
15
# File 'lib/neo4j/driver/record.rb', line 7

def initialize(keys, values)
  @keys = keys
  @values = values
  # Field keys arrive already symbolized (Session/Transaction map the
  # RUN response fields with &:to_sym), so the map is symbol-keyed and
  # to_h returns symbol keys like the JRuby flavour. Every key in the
  # driver is stored as a symbol; retrieval by string is tolerated (#[]).
  @map = keys.zip(values).to_h
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



17
18
19
# File 'lib/neo4j/driver/record.rb', line 17

def keys
  @keys
end

#valuesObject (readonly)

Returns the value of attribute values.



17
18
19
# File 'lib/neo4j/driver/record.rb', line 17

def values
  @values
end

Instance Method Details

#[](key) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/neo4j/driver/record.rb', line 19

def [](key)
  case key
  when Integer
    @values[key]
  when String, Symbol
    @map[key.to_sym]
  else
    raise ArgumentError, "Invalid key type: #{key.class}"
  end
end

#eachObject



38
39
40
# File 'lib/neo4j/driver/record.rb', line 38

def each(&)
  @map.each(&)
end

#firstObject



30
31
32
# File 'lib/neo4j/driver/record.rb', line 30

def first
  @values.first
end

#to_hObject



34
35
36
# File 'lib/neo4j/driver/record.rb', line 34

def to_h
  @map.dup
end