Class: Neo4j::Core::CypherSession::Result

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/neo4j/core/cypher_session/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(columns, rows) ⇒ Result

Returns a new instance of Result.



11
12
13
14
15
# File 'lib/neo4j/core/cypher_session/result.rb', line 11

def initialize(columns, rows)
  @columns = columns.map(&:to_sym)
  @rows = rows
  @struct_class = Struct.new(:index, *@columns)
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



9
10
11
# File 'lib/neo4j/core/cypher_session/result.rb', line 9

def columns
  @columns
end

#rowsObject (readonly)

Returns the value of attribute rows.



9
10
11
# File 'lib/neo4j/core/cypher_session/result.rb', line 9

def rows
  @rows
end

Instance Method Details

#eachObject



19
20
21
22
23
# File 'lib/neo4j/core/cypher_session/result.rb', line 19

def each
  structs.each do |struct|
    yield struct
  end
end

#hashesObject



31
32
33
34
35
# File 'lib/neo4j/core/cypher_session/result.rb', line 31

def hashes
  @hashes ||= rows.map do |row|
    Hash[@columns.zip(row)]
  end
end

#structsObject



25
26
27
28
29
# File 'lib/neo4j/core/cypher_session/result.rb', line 25

def structs
  @structs ||= rows.each_with_index.map do |row, index|
    @struct_class.new(index, *row)
  end
end