class Neo4j::Cypher::ResultWrapper

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. @notice The result is a once forward read only Enumerable, work if you need to read the result twice - use to_a

@example

result = Neo4j.query(@a, @b){|a,b| node(a,b).as(:n)}
r = @query_result.to_a # can only loop once
r.size.should == 2
r.first.should include(:n)
r[0][:n].neo_id.should == @a.neo_id
r[1][:n].neo_id.should == @b.neo_id

Attributes

source[R]

@return the original result from the Neo4j Cypher Engine, once forward read only !

Public Class Methods

new(source) click to toggle source
   # File lib/neo4j-cypher/result_wrapper.rb
23 def initialize(source)
24   @source = source
25   @unread = true
26 end

Public Instance Methods

columns() click to toggle source

@return [Array<Symbol>] the columns in the query result

   # File lib/neo4j-cypher/result_wrapper.rb
29 def columns
30   @source.columns.map { |x| x.to_sym }
31 end
each() { |symbolize_row_keys(row)| ... } click to toggle source

for the Enumerable contract

   # File lib/neo4j-cypher/result_wrapper.rb
34 def each
35   raise ResultsAlreadyConsumedException unless @unread
36 
37   if block_given?
38     @unread = false
39     @source.each { |row| yield symbolize_row_keys(row) }
40   else
41     Enumerator.new(self)
42   end
43 end

Private Instance Methods

symbolize_row_keys(row) click to toggle source

Maps each row so that we can use symbols for column names.

   # File lib/neo4j-cypher/result_wrapper.rb
48 def symbolize_row_keys(row)
49   out = {} # move to a real hash!
50   row.each do |key, value|
51     out[key.to_sym] = value.respond_to?(:wrapper) ? value.wrapper : value
52   end
53   out
54 end