class Tablo::Table

Included Modules

Defined in:

table.cr

Constant Summary

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

Constructors

Instance Method Summary

Constructor Detail

def self.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


[View source]
def self.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


[View source]

Instance Method Detail

def 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


[View source]
def 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


[View source]
def formatted_body_row(source, index, with_header = false) #

Returns a formatted body row, including headers where appropriate


[View source]
def formatted_header #

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


[View source]
def horizontal_rule(line : TLine) #

Compute horizontal rule, with connectors depending on line type


[View source]
def 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.


[View source]
def to_s(io) #

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


[View source]
def zzz_shrinkwrap!(max_table_width = 0, min_table_width = 0) #

[View source]