Class: PT::DataTable
- Inherits:
-
Object
show all
- Extended by:
- Hirb::Console
- Defined in:
- lib/pt/data_table.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(dataset) ⇒ DataTable
Returns a new instance of DataTable.
10
11
12
|
# File 'lib/pt/data_table.rb', line 10
def initialize(dataset)
@rows = dataset.map{ |row| DataRow.new(row, dataset) }
end
|
Class Method Details
.fields ⇒ Object
43
44
45
|
# File 'lib/pt/data_table.rb', line 43
def self.fields
[]
end
|
47
48
49
|
# File 'lib/pt/data_table.rb', line 47
def self.
[]
end
|
Instance Method Details
#[](pos) ⇒ Object
34
35
36
37
|
# File 'lib/pt/data_table.rb', line 34
def [](pos)
pos = pos.to_i
(pos < 1 || pos > @rows.length) ? nil : @rows[pos-1].record
end
|
#length ⇒ Object
39
40
41
|
# File 'lib/pt/data_table.rb', line 39
def length
@rows.length
end
|
#print(config = {}) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/pt/data_table.rb', line 14
def print(config={})
if @rows.empty?
puts "\n#{'-- empty list --'.center(36)}\n"
else
max_width = Hirb::Util.detect_terminal_size()[0]
if config[:max_width] && config[:max_width] < max_width
max_width = config[:max_width]
end
= [:num]
+= self.class..present? ? self.class. : self.class.fields
self.class.table @rows, :fields => [:num] + self.class.fields,
:change_fields => %w{num pt_id},
:unicode => true, :description => false,
:max_width => max_width
end
end
|