Class: Trlo::DataTable
- Inherits:
-
Object
show all
- Extended by:
- Hirb::Console
- Defined in:
- lib/trlo/data_table.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(dataset) ⇒ DataTable
Returns a new instance of DataTable.
8
9
10
|
# File 'lib/trlo/data_table.rb', line 8
def initialize(dataset)
@rows = dataset.map{ |row| DataRow.new(row, dataset) }
end
|
Class Method Details
.fields ⇒ Object
31
32
33
|
# File 'lib/trlo/data_table.rb', line 31
def self.fields
[]
end
|
Instance Method Details
#[](pos) ⇒ Object
22
23
24
25
|
# File 'lib/trlo/data_table.rb', line 22
def [](pos)
pos = pos.to_i
(pos < 1 || pos > @rows.length) ? nil : @rows[pos-1].record
end
|
#length ⇒ Object
27
28
29
|
# File 'lib/trlo/data_table.rb', line 27
def length
@rows.length
end
|
#print(config = {}) ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/trlo/data_table.rb', line 12
def print(config={})
if @rows.empty?
puts "\n#{'-- empty list --'.center(36)}\n"
else
self.class.table @rows, :fields => [:num] + self.class.fields,
:unicode => true, :description => false,
:max_width => config[:max_width]
end
end
|