Class: Tina4::GraphResult

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tina4/graph.rb

Overview

A raw-query result — records + columns, same shape as DatabaseResult.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records: nil, columns: nil) ⇒ GraphResult

Returns a new instance of GraphResult.



170
171
172
173
# File 'lib/tina4/graph.rb', line 170

def initialize(records: nil, columns: nil)
  @records = records || []
  @columns = columns || []
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



168
169
170
# File 'lib/tina4/graph.rb', line 168

def columns
  @columns
end

#recordsObject (readonly)

Returns the value of attribute records.



168
169
170
# File 'lib/tina4/graph.rb', line 168

def records
  @records
end

Instance Method Details

#each(&block) ⇒ Object



192
193
194
# File 'lib/tina4/graph.rb', line 192

def each(&block)
  @records.each(&block)
end

#lengthObject Also known as: size



196
197
198
# File 'lib/tina4/graph.rb', line 196

def length
  @records.length
end

#scalarObject



179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/tina4/graph.rb', line 179

def scalar
  return nil if @records.empty?

  first = @records[0]
  if first.is_a?(Hash)
    first.values.first
  elsif first.is_a?(Array)
    first.empty? ? nil : first[0]
  else
    first
  end
end

#to_aObject



175
176
177
# File 'lib/tina4/graph.rb', line 175

def to_a
  @records
end