IO ANSI Table v0.4.19 IO.ANSI.Table.Column View Source

Functions related to the columns of a table.

Link to this section Summary

Functions

Returns the specs attribute of a header

Spreads a width given an element and its align attribute

Returns a list of column widths capped by maximum width

Link to this section Types

Link to this section Functions

Link to this function find_attr(header, specs, default_attr) View Source
find_attr(any(), [spec()], attr()) :: any() | attr()

Returns the specs attribute of a header.

Examples

iex> alias IO.ANSI.Table.Column
iex> sort_specs = ["dept", desc: "hired"]
iex> {
...>   Column.find_attr("dept" , sort_specs, :asc),
...>   Column.find_attr("hired", sort_specs, :asc),
...>   Column.find_attr("job"  , sort_specs, :asc)
...> }
{:asc, :desc, nil}
Link to this function spread(width, elem, align_attr) View Source

Spreads a width given an element and its align attribute.

Examples

iex> alias IO.ANSI.Table.Column
iex> {
...>   Column.spread(7, "name", :left  ),
...>   Column.spread(7, "name", :center),
...>   Column.spread(7, "name", :right )
...> }
{[0, 4, 3], [1, 4, 2], [3, 4, 0]}

iex> alias IO.ANSI.Table.Column
iex> {
...>   Column.spread(3, "name", :left  ),
...>   Column.spread(3, "name", :center),
...>   Column.spread(3, "name", :right )
...> }
{[0, 3, 0], [0, 3, 0], [0, 3, 0]}

iex> alias IO.ANSI.Table.Column
iex> {
...>   Column.spread(10, "CHEETAH", :left  ),
...>   Column.spread(10, "CHEETAH", :center),
...>   Column.spread(10, "CHEETAH", :right )
...> }
{[0, 21, 3], [1, 21, 2], [3, 21, 0]}

iex> alias IO.ANSI.Table.Column
iex> {
...>   Column.spread(7, "CHEETAH", :left  ),
...>   Column.spread(7, "CHEETAH", :center),
...>   Column.spread(7, "CHEETAH", :right )
...> }
{[0, 21, 0], [0, 21, 0], [0, 21, 0]}
Link to this function widths(columns, max_width \\ 99) View Source
widths([t()], width()) :: [width()]

Returns a list of column widths capped by maximum width.

Examples

iex> alias IO.ANSI.Table.Column
iex> data = [["cat", "wombat", "elk"], ["mongoose", "ant", "gnu"]]
iex> Column.widths(data)
[6, 8]

iex> alias IO.ANSI.Table.Column
iex> data = [["cat", "wombat", "elk"], ["mongoose", "ant", "gnu"]]
iex> Column.widths(data, 7)
[6, 7]

iex> alias IO.ANSI.Table.Column
iex> data = [["CHEETAH", "elk"], ["mongoose", "ant"]]
iex> Column.widths(data)
[7, 8]