Issues v0.1.0 Issues.TableFormatter View Source

Link to this section Summary

Functions

Return a format string that hard codes the widths of a set of columns. We put " | " between each column

Takes a list of row data, where each row is a Map, and a list of headers. Prints a table to STDOUT of the data from each row identified by each header. That is, each header identifies a column, and those columns are extracted and printed from the rows. We calculate the width of each column to fit the longest element in that column

Return a binary (string) version of our parameter.

Examples

iex> Issues.TableFormatter.printable("a")
"a"
iex> Issues.TableFormatter.printable(99)
"99"

Given a list containing rows of data, a list containing the header selectors, and a format string, write the extracted data under control of the format string

Generate the line that goes below the column headings. It is a string of hyphens, with + signs where the vertical bar between the columns goes

Given a list of rows, where each row contains a keyed list of columns, return a list containing lists of the data in each column. The headers parameter contains the list of columns to extract

Given a list containing sublists, where each sublist contains the data for a column, return a list containing the maximum width of each column

Link to this section Functions

Link to this function format_for(column_widths) View Source

Return a format string that hard codes the widths of a set of columns. We put " | " between each column.

Example

iex> widths = [5,6,99]
iex> Issues.TableFormatter.format_for(widths)
"~-5s | ~-6s | ~-99s~n"

Return a binary (string) version of our parameter.

Examples

iex> Issues.TableFormatter.printable("a")
"a"
iex> Issues.TableFormatter.printable(99)
"99"
Link to this function puts_in_columns(data_by_columns, format) View Source

Given a list containing rows of data, a list containing the header selectors, and a format string, write the extracted data under control of the format string.

Link to this function puts_one_line_in_columns(fields, format) View Source
Link to this function separator(column_widths) View Source

Generate the line that goes below the column headings. It is a string of hyphens, with + signs where the vertical bar between the columns goes.

Example

iex> widths = [5,6,9]
  iex> Issues.TableFormatter.separator(widths)
  "------+--------+----------"
Link to this function split_into_columns(rows, headers) View Source

Given a list of rows, where each row contains a keyed list of columns, return a list containing lists of the data in each column. The headers parameter contains the list of columns to extract

Example

iex> list = [Enum.into([{"a", "1"},{"b", "2"},{"c", "3"}], %{}),
...>         Enum.into([{"a", "4"},{"b", "5"},{"c", "6"}], %{})]
iex> Issues.TableFormatter.split_into_columns(list, [ "a", "b", "c" ])
[ ["1", "4"], ["2", "5"], ["3", "6"] ]

Given a list containing sublists, where each sublist contains the data for a column, return a list containing the maximum width of each column

Example

iex> data = [ [ "cat", "wombat", "elk"], ["mongoose", "ant", "gnu"]]
iex> Issues.TableFormatter.widths_of(data)
[ 6, 8 ]