Class: Jvertica::Row
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/jvertica.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(col_labels, col_labels_d, values, rownum) ⇒ Row
Returns a new instance of Row.
321
322
323
324
325
326
|
# File 'lib/jvertica.rb', line 321
def initialize col_labels, col_labels_d, values, rownum
@labels = col_labels
@labels_d = col_labels_d
@values = values
@rownum = rownum
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symb, *args) ⇒ Object
328
329
330
331
332
333
334
335
336
|
# File 'lib/jvertica.rb', line 328
def method_missing symb, *args
if vidx = @labels_d.index(symb.to_s.downcase)
@values[vidx]
elsif @values.respond_to? symb
@values.send symb, *args
else
raise NoMethodError.new("undefined method or attribute `#{symb}'")
end
end
|
Instance Attribute Details
#labels ⇒ Object
Also known as:
keys
Returns the value of attribute labels.
263
264
265
|
# File 'lib/jvertica.rb', line 263
def labels
@labels
end
|
#rownum ⇒ Object
Returns the value of attribute rownum.
263
264
265
|
# File 'lib/jvertica.rb', line 263
def rownum
@rownum
end
|
#values ⇒ Object
Returns the value of attribute values.
263
264
265
|
# File 'lib/jvertica.rb', line 263
def values
@values
end
|
Instance Method Details
#[](*idx) ⇒ Object
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
# File 'lib/jvertica.rb', line 268
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(&blk) ⇒ Object
285
286
287
288
289
|
# File 'lib/jvertica.rb', line 285
def each(&blk)
@values.each do |v|
yield v
end
end
|
#eql?(other) ⇒ Boolean
Also known as:
==
307
308
309
|
# File 'lib/jvertica.rb', line 307
def eql? other
self.hash == other.hash
end
|
#hash ⇒ Object
311
312
313
|
# File 'lib/jvertica.rb', line 311
def hash
@labels.zip(@values).sort.hash
end
|
#inspect ⇒ Object
291
292
293
294
295
296
297
|
# File 'lib/jvertica.rb', line 291
def inspect
strs = []
@labels.each do |col|
strs << "#{col}: #{self[col] || '(null)'}"
end
'[' + strs.join(', ') + ']'
end
|
#join(sep = $OUTPUT_FIELD_SEPARATOR) ⇒ Object
303
304
305
|
# File 'lib/jvertica.rb', line 303
def join sep = $OUTPUT_FIELD_SEPARATOR
to_a.join sep
end
|
#to_a ⇒ Object
299
300
301
|
# File 'lib/jvertica.rb', line 299
def to_a
@values
end
|
#to_h ⇒ Object
315
316
317
|
# File 'lib/jvertica.rb', line 315
def to_h
Hash[@labels.zip @values]
end
|