Class: Trlo::DataTable

Inherits:
Object
  • Object
show all
Extended by:
Hirb::Console
Defined in:
lib/trlo/data_table.rb

Direct Known Subclasses

BoardTable, MembersTable, TasksTable

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

.fieldsObject



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

#lengthObject



27
28
29
# File 'lib/trlo/data_table.rb', line 27

def length
  @rows.length
end


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