class Tablo::Table
- Tablo::Table
- Reference
- Object
Included Modules
- Enumerable(Tablo::Row)
Defined in:
table.crConstant Summary
-
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
-
.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
Instance Method Summary
-
#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
-
#each(&)
Calls the given block once for each {Row} in the Table, passing that {Row} as parameter.
-
#formatted_body_row(source, index, with_header = false)
Returns a formatted body row, including headers where appropriate
-
#formatted_header
Returns an "ASCII" graphical representation of the Table column (possibly multilines) headers.
-
#horizontal_rule(line : TLine)
Compute horizontal rule, with connectors depending on line type
-
#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.
-
#to_s(io)
Returns graphical "ASCII" representation of the Table, suitable for display in a fixed-width font.
- #zzz_shrinkwrap!(max_table_width = 0, min_table_width = 0)
Constructor Detail
Creates a new Table instance, with block
sources
is the only mandatory parameter, all other have default values
Creates a new Table instance, without block
Instance Method Detail
Add a column to the table
This method must be used with a block defining the extracting logic
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
Returns a formatted body row, including headers where appropriate
Returns an "ASCII" graphical representation of the Table column (possibly multilines) headers.
Compute horizontal rule, with connectors depending on line type
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.
Returns graphical "ASCII" representation of the Table, suitable for display in a fixed-width font.