Tabular
Tabular is a reader for data in ascii table format. It allows you to read string data formatted like this:
|------------------+--------------------| | name | dob | |------------------+--------------------| | Malcolm Reynolds | September 20, 2468 | |------------------+--------------------| | Zoe Washburne | February 15, 2484 | |------------------+--------------------|
In Ascii Tables For Clearer Testing I discuss using ascii tables to improve comprehension of software tests.
Installation
The package can be installed by adding tabular
to your list of dependencies in mix.exs
:
def deps do
[
{:tabular, "~> 0.1.0"}
]
end
Usage
Rows are returned as either lists of lists or lists of maps.
|-----------------------+------------------------------+-----------------------------------| | **Ascii Table Value** | **Returned Value** | **Notes** | |-----------------------+------------------------------+-----------------------------------| | Malcolm Reynolds | "Malcolm Reynolds" | Most values returned as string | |-----------------------+------------------------------+-----------------------------------| | 123 | "123" | including numbers | |-----------------------+------------------------------+-----------------------------------| | wrapped strings are | "wrapped strings are folded" | Similar to yaml, wrapped | | folded | | strings are folded with a single | | | | space replacing the new line | |-----------------------+------------------------------+-----------------------------------| | | nil | nil is returned for blank values | |-----------------------+------------------------------+-----------------------------------| | nil | nil | nil, true, and false are | | | | special values | |-----------------------+------------------------------+-----------------------------------| | true | true | | |-----------------------+------------------------------+-----------------------------------| | false | false | | |-----------------------+------------------------------+-----------------------------------| | :foo | :foo | Values starting with a colon are | | | | returned as atoms | |-----------------------+------------------------------+-----------------------------------|
Reading a String
Tabular.to_list_of_lists_no_hd(table)
|> Enum.each(fn [col1, col2, col3] = row ->
# use row or column data here...
end
More examples can be found in the Examples of Testing With ASCII Tables repo.
The docs can be found at https://hexdocs.pm/tabular.