Class: Vertica::Result

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/vertica/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#columnsObject (readonly)

Returns the value of attribute columns.



4
5
6
# File 'lib/vertica/result.rb', line 4

def columns
  @columns
end

#noticeObject

Returns the value of attribute notice.



6
7
8
# File 'lib/vertica/result.rb', line 6

def notice
  @notice
end

#rowsObject (readonly)

Returns the value of attribute rows.



5
6
7
# File 'lib/vertica/result.rb', line 5

def rows
  @rows
end

#tagObject

Returns the value of attribute tag.



6
7
8
# File 'lib/vertica/result.rb', line 6

def tag
  @tag
end

Instance Method Details

#[](row, col = nil) ⇒ Object



58
59
60
# File 'lib/vertica/result.rb', line 58

def [](row, col = nil)
  col.nil? ? row[row] : rows[row][col]
end

#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=(message)
  @columns = message.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

Returns:

  • (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_countObject Also known as: size, length



64
65
66
# File 'lib/vertica/result.rb', line 64

def row_count
  @rows.size
end

#the_valueObject



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