Class: JDBCHelper::Connection::Row
- Inherits:
-
Object
- Object
- JDBCHelper::Connection::Row
show all
- Includes:
- Enumerable
- Defined in:
- lib/jdbc-helper/connection/row.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symb, *args) ⇒ Object
Performs better than defining methods
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/jdbc-helper/connection/row.rb', line 124
def method_missing(symb, *args)
if vidx = @labels_d.index(symb.to_s.downcase)
begin
@values[vidx]
rescue NameError
raise NoMethodError.new("undefined method or attribute `#{symb}'")
end
elsif @values.respond_to?(symb)
@values.send(symb, *args)
else
raise NoMethodError.new("undefined method or attribute `#{symb}'")
end
end
|
Instance Attribute Details
#labels ⇒ Array
Also known as:
keys
Returns Labels of the columns.
28
29
30
|
# File 'lib/jdbc-helper/connection/row.rb', line 28
def labels
@labels
end
|
#rownum ⇒ Fixnum
Returns Sequential row number assigned within the scope of the query.
32
33
34
|
# File 'lib/jdbc-helper/connection/row.rb', line 32
def rownum
@rownum
end
|
#values ⇒ Array
30
31
32
|
# File 'lib/jdbc-helper/connection/row.rb', line 30
def values
@values
end
|
Instance Method Details
#[](idx) ⇒ Object
#[](offset, len) ⇒ Array
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/jdbc-helper/connection/row.rb', line 44
def [](*idx)
return @values[*idx] if idx.length > 1
idx = idx.first
case idx
when Fixnum
raise RangeError.new("Index out of bound") if idx >= @values.length
@values[idx]
when String, Symbol
vidx = @labels_d.index(idx.to_s.downcase) or
raise NameError.new("Unknown column label: #{idx}")
@values[vidx]
else
@values[idx]
end
end
|
#each {|Object| ... } ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/jdbc-helper/connection/row.rb', line 64
def each(&blk)
@values.each { | v | yield v }
end
|
#eql?(other) ⇒ Boolean
Also known as:
==
97
98
99
|
# File 'lib/jdbc-helper/connection/row.rb', line 97
def eql?(other)
self.hash == other.hash
end
|
#hash ⇒ Object
101
102
103
|
# File 'lib/jdbc-helper/connection/row.rb', line 101
def hash @labels.zip(@values).sort.hash
end
|
#inspect ⇒ String
73
74
75
76
77
78
79
|
# File 'lib/jdbc-helper/connection/row.rb', line 73
def inspect
strs = []
@labels.each do | col |
strs << "#{col}: #{self[col] || '(null)'}"
end
'[' + strs.join(', ') + ']'
end
|
#join(sep = $,) ⇒ String
92
93
94
|
# File 'lib/jdbc-helper/connection/row.rb', line 92
def join(sep = $,)
to_a.join(sep)
end
|
#to_a ⇒ Array
87
88
89
|
# File 'lib/jdbc-helper/connection/row.rb', line 87
def to_a
@values
end
|
#to_s ⇒ String
82
83
84
|
# File 'lib/jdbc-helper/connection/row.rb', line 82
def to_s
@values.to_s
end
|