Class: Neo4j::Cypher::ResultWrapper
- Inherits:
-
Object
- Object
- Neo4j::Cypher::ResultWrapper
- Includes:
- Enumerable
- Defined in:
- lib/neo4j-cypher/result_wrapper.rb
Overview
Wraps the Cypher query result. Loads the node and relationships wrapper if possible and use symbol as column keys. This is typically used in the native neo4j bindings since result does is not a Ruby enumerable with symbols as keys.
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
The original result from the Neo4j Cypher Engine, once forward read only !.
Instance Method Summary collapse
-
#columns ⇒ Array<Symbol>
The columns in the query result.
-
#each ⇒ Object
for the Enumerable contract.
-
#initialize(source) ⇒ ResultWrapper
constructor
A new instance of ResultWrapper.
-
#map(row) ⇒ Object
Maps each row so that we can use symbols for column names.
Constructor Details
#initialize(source) ⇒ ResultWrapper
Returns a new instance of ResultWrapper.
21 22 23 |
# File 'lib/neo4j-cypher/result_wrapper.rb', line 21 def initialize(source) @source = source end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the original result from the Neo4j Cypher Engine, once forward read only !.
19 20 21 |
# File 'lib/neo4j-cypher/result_wrapper.rb', line 19 def source @source end |
Instance Method Details
#columns ⇒ Array<Symbol>
Returns the columns in the query result.
26 27 28 |
# File 'lib/neo4j-cypher/result_wrapper.rb', line 26 def columns @source.columns.map { |x| x.to_sym } end |
#each ⇒ Object
for the Enumerable contract
31 32 33 |
# File 'lib/neo4j-cypher/result_wrapper.rb', line 31 def each @source.each { |row| yield map(row) } end |
#map(row) ⇒ Object
Maps each row so that we can use symbols for column names.
37 38 39 40 41 42 43 |
# File 'lib/neo4j-cypher/result_wrapper.rb', line 37 def map(row) out = {} # move to a real hash! row.each do |key, value| out[key.to_sym] = value.respond_to?(:wrapper) ? value.wrapper : value end out end |