Class: VoltRb::VoltTable

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/voltrb/volt_table.rb

Overview

This object contains one or more rows (a rowset). Enumerable is implemented so we can access the rows via the usual each, all, first, last.

first_row = response.results[0].first

Each row is a hash with the symbolized column names for keys.

puts first_row[:MY_COLUMN]

We can get a list of columns via schema.

Instance Method Summary collapse

Constructor Details

#initialize(hash_data) ⇒ VoltTable

Returns a new instance of VoltTable.



13
14
15
# File 'lib/voltrb/volt_table.rb', line 13

def initialize(hash_data)
  @raw = hash_data
end

Instance Method Details

#allObject



30
31
32
# File 'lib/voltrb/volt_table.rb', line 30

def all
  self.inject([]) { |o,e| o << e; o }
end

#countObject



46
47
48
# File 'lib/voltrb/volt_table.rb', line 46

def count
  @raw["data"].size
end

#eachObject



25
26
27
28
# File 'lib/voltrb/volt_table.rb', line 25

def each
  # ToDo: Benchmark, benchmark, benchmark.
  @raw["data"].each { |r| yield hydrate_row(r) }
end

#empty?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/voltrb/volt_table.rb', line 42

def empty?
  @raw["data"].empty?
end

#firstObject



34
35
36
# File 'lib/voltrb/volt_table.rb', line 34

def first
  hydrate_row(@raw["data"].first)
end

#lastObject



38
39
40
# File 'lib/voltrb/volt_table.rb', line 38

def last
  hydrate_row(@raw["data"].last)
end

#schemaObject



21
22
23
# File 'lib/voltrb/volt_table.rb', line 21

def schema
  @schema ||= hydrate_schema
end

#statusObject



17
18
19
# File 'lib/voltrb/volt_table.rb', line 17

def status
  @status ||= @raw["status"]
end