Class: TTY::Table::ColumnSet
- Inherits:
-
Object
- Object
- TTY::Table::ColumnSet
- Extended by:
- Delegatable
- Includes:
- Equatable
- Defined in:
- lib/tty/table/column_set.rb
Overview
A class that represents table columns properties.
Instance Attribute Summary collapse
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Attributes included from Equatable
Instance Method Summary collapse
-
#extract_widths! ⇒ Array
private
Calcualte maximum column widths.
-
#initialize(table) ⇒ ColumnSet
constructor
A new instance of ColumnSet.
-
#total_width ⇒ Integer
Calculate total table width.
Methods included from Delegatable
Methods included from Equatable
#attr_reader, included, #inherited
Constructor Details
#initialize(table) ⇒ ColumnSet
Returns a new instance of ColumnSet.
15 16 17 |
# File 'lib/tty/table/column_set.rb', line 15 def initialize(table) @table = table end |
Instance Attribute Details
#table ⇒ Object (readonly)
Returns the value of attribute table.
11 12 13 |
# File 'lib/tty/table/column_set.rb', line 11 def table @table end |
Instance Method Details
#extract_widths! ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Calcualte maximum column widths
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tty/table/column_set.rb', line 33 def extract_widths! return column_widths unless column_widths.empty? rows = table.to_a data = table.header ? rows + [table.header] : rows colcount = data.max { |row_a, row_b| row_a.size <=> row_b.size }.size table.column_widths = find_maximas colcount, data self end |
#total_width ⇒ Integer
Calculate total table width
24 25 26 |
# File 'lib/tty/table/column_set.rb', line 24 def total_width column_widths.reduce(:+) end |