class

Tablo::Table

Inherits Enumerable < Reference < Object

Constants

DEFAULT_COLUMN_PADDING = 1
DEFAULT_COLUMN_WIDTH = 12
DEFAULT_TRUNCATION_INDICATOR = '~'
PADDING_CHARACTER = ' '

Constructors

new(sources, default_column_width : Int32 = DEFAULT_COLUMN_WIDTH, column_padding : Int32 = DEFAULT_COLUMN_PADDING, header_frequency : Int32 | Nil = 0, wrap_header_cells_to : Int32 | Nil = nil, wrap_body_cells_to : Int32 | Nil = nil, default_header_alignment : Justify = Justify::None, truncation_indicator : Char = DEFAULT_TRUNCATION_INDICATOR, connectors : String = CONNECTORS_TEXT_CLASSIC, style : String = STYLE_ALL_BORDERS, &)

Creates a new Table instance, with block

sources is the only mandatory parameter, all other have default values

Source
new(sources, default_column_width : Int32 = DEFAULT_COLUMN_WIDTH, column_padding : Int32 = DEFAULT_COLUMN_PADDING, header_frequency : Int32 | Nil = 0, wrap_header_cells_to : Int32 | Nil = nil, wrap_body_cells_to : Int32 | Nil = nil, default_header_alignment : Justify = Justify::None, truncation_indicator : Char = DEFAULT_TRUNCATION_INDICATOR, connectors : String = CONNECTORS_TEXT_CLASSIC, style : String = STYLE_ALL_BORDERS)

Creates a new Table instance, without block

Source

Instance methods

add_column(label, header = nil, align_header = Justify::None, align_body = Justify::None, width = nil, formatter : CellType -> String = ->(n : CellType) do n.to_s end, styler : CellType -> String = ->(n : CellType) do n.to_s end, &extractor : Array(CellType) -> CellType)

Add a column to the table

This method must be used with a block defining the extracting logic

Source
each

Calls the given block once for each {Row} in the Table, passing that {Row} as parameter.

When printed, the first row will visually include the headers (assuming these were not disabled when the Table was initialized). Iterates on source elements, creating formatted rows dynamically

Source
formatted_body_row(source, index, with_header = false)

Returns a formatted body row, including headers where appropriate

Source
formatted_header

Returns an "ASCII" graphical representation of the Table column (possibly multilines) headers.

Source
horizontal_rule(line : TLine)

Compute horizontal rule, with connectors depending on line type

Source
shrinkwrap!(max_min_width = 0)

Reset all the column widths so that each column is just wide enough to accommodate its header text as well as the formatted content of each of its cells for the entire collection, together with a single character of padding on either side of the column, without any wrapping.

Note that calling this method will cause the entire source to be traversed and all the column extractors and formatters to be applied in order to calculate the required widths.

Source
to_s(io)

Returns graphical "ASCII" representation of the Table, suitable for display in a fixed-width font.

Source
zzz_shrinkwrap!(max_table_width = 0, min_table_width = 0)
Source