Class: VoltRb::VoltTable
- Inherits:
-
Object
- Object
- VoltRb::VoltTable
- 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
- #all ⇒ Object
- #count ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
-
#initialize(hash_data) ⇒ VoltTable
constructor
A new instance of VoltTable.
- #last ⇒ Object
- #schema ⇒ Object
- #status ⇒ Object
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
#all ⇒ Object
30 31 32 |
# File 'lib/voltrb/volt_table.rb', line 30 def all self.inject([]) { |o,e| o << e; o } end |
#count ⇒ Object
46 47 48 |
# File 'lib/voltrb/volt_table.rb', line 46 def count @raw["data"].size end |
#each ⇒ Object
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
42 43 44 |
# File 'lib/voltrb/volt_table.rb', line 42 def empty? @raw["data"].empty? end |
#first ⇒ Object
34 35 36 |
# File 'lib/voltrb/volt_table.rb', line 34 def first hydrate_row(@raw["data"].first) end |
#last ⇒ Object
38 39 40 |
# File 'lib/voltrb/volt_table.rb', line 38 def last hydrate_row(@raw["data"].last) end |
#schema ⇒ Object
21 22 23 |
# File 'lib/voltrb/volt_table.rb', line 21 def schema @schema ||= hydrate_schema end |
#status ⇒ Object
17 18 19 |
# File 'lib/voltrb/volt_table.rb', line 17 def status @status ||= @raw["status"] end |