Class: IO::Table
- Inherits:
-
Object
- Object
- IO::Table
- Defined in:
- lib/term/table.rb
Overview
Table Component.
Constant Summary collapse
- BORDER =
the table border character.
{ sep: '│', line: '-', top: ['┌', '┬', '┐'], mid: ['├', '┼', '┤'], bot: ['└', '┴', '┘'] }.freeze
Instance Method Summary collapse
-
#<<(row) ⇒ self
add row to the table.
-
#initialize ⇒ Table
constructor
A new instance of Table.
-
#to_s ⇒ String
display table.
Constructor Details
#initialize ⇒ Table
Returns a new instance of Table.
18 19 20 21 22 |
# File 'lib/term/table.rb', line 18 def initialize @data = [] @size = [] @column_width = [] end |
Instance Method Details
#<<(row) ⇒ self
add row to the table
28 29 30 31 32 |
# File 'lib/term/table.rb', line 28 def <<(row) @data << row.map(&:to_s) @size << row.map { |cell| cell.to_s.display_width } self end |
#to_s ⇒ String
display table.
37 38 39 40 41 42 43 |
# File 'lib/term/table.rb', line 37 def to_s @column_width = calc_column_width res = get_border_row(BORDER[:top]) res << @data.map { |row| get_content_row(row, BORDER[:sep]) } .join(get_border_row(BORDER[:mid])) res << get_border_row(BORDER[:bot]) end |