Class: Vertica::Result
- Inherits:
-
Object
- Object
- Vertica::Result
- Includes:
- Enumerable
- Defined in:
- lib/vertica/result.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#notice ⇒ Object
Returns the value of attribute notice.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#tag ⇒ Object
Returns the value of attribute tag.
Instance Method Summary collapse
- #add_row(row) ⇒ Object
- #descriptions=(message) ⇒ Object
- #each_row(&block) ⇒ Object (also: #each)
- #empty? ⇒ Boolean
- #format_row(row_data) ⇒ Object
- #format_row_as_array(row_data) ⇒ Object
- #format_row_as_hash(row_data) ⇒ Object
-
#initialize(row_style = :hash) ⇒ Result
constructor
A new instance of Result.
- #row_count ⇒ Object (also: #size, #length)
- #the_value ⇒ Object
Constructor Details
#initialize(row_style = :hash) ⇒ Result
Returns a new instance of Result.
8 9 10 11 |
# File 'lib/vertica/result.rb', line 8 def initialize(row_style = :hash) @row_style = row_style @rows = [] end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
4 5 6 |
# File 'lib/vertica/result.rb', line 4 def columns @columns end |
#notice ⇒ Object
Returns the value of attribute notice.
6 7 8 |
# File 'lib/vertica/result.rb', line 6 def notice @notice end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
5 6 7 |
# File 'lib/vertica/result.rb', line 5 def rows @rows end |
#tag ⇒ Object
Returns the value of attribute tag.
6 7 8 |
# File 'lib/vertica/result.rb', line 6 def tag @tag end |
Instance Method Details
#add_row(row) ⇒ Object
38 39 40 |
# File 'lib/vertica/result.rb', line 38 def add_row(row) @rows << row end |
#descriptions=(message) ⇒ Object
13 14 15 |
# File 'lib/vertica/result.rb', line 13 def descriptions=() @columns = .fields.map { |fd| Vertica::Column.new(fd) } end |
#each_row(&block) ⇒ Object Also known as: each
42 43 44 |
# File 'lib/vertica/result.rb', line 42 def each_row(&block) @rows.each(&block) end |
#empty? ⇒ Boolean
46 47 48 |
# File 'lib/vertica/result.rb', line 46 def empty? @rows.empty? end |
#format_row(row_data) ⇒ Object
26 27 28 |
# File 'lib/vertica/result.rb', line 26 def format_row(row_data) send("format_row_as_#{@row_style}", row_data) end |
#format_row_as_array(row_data) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/vertica/result.rb', line 30 def format_row_as_array(row_data) row = [] row_data.values.each_with_index do |value, idx| row << columns[idx].convert(value) end row end |
#format_row_as_hash(row_data) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/vertica/result.rb', line 17 def format_row_as_hash(row_data) row = {} row_data.values.each_with_index do |value, idx| col = columns[idx] row[col.name] = col.convert(value) end row end |
#row_count ⇒ Object Also known as: size, length
60 61 62 |
# File 'lib/vertica/result.rb', line 60 def row_count @rows.size end |
#the_value ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/vertica/result.rb', line 50 def the_value if empty? nil else @row_style == :array ? rows[0][0] : rows[0][columns[0].name] end end |