Tabular v1.2.1 Tabular View Source

Tabular converts an ascii table string into either a list of lists or a list of maps.

Link to this section Summary

Functions

Converts an ascii table to a list of lists.

Converts an ascii table to a list of lists, omitting the header row.

Converts an ascii table to a list of maps.

Link to this section Functions

Link to this function

to_list_of_lists(ascii_table, opts \\ [header: true]) View Source

Converts an ascii table to a list of lists.

Examples

iex> ascii_table = """
...> |---------------+--------------------|
...> | name          | dob                |
...> |---------------+--------------------|
...> | Malcolm       | September 20, 2468 |
...> | Reynolds      |                    |
...> |---------------+--------------------|
...> | Zoe Washburne | February 15, 2484  |
...> |---------------+--------------------|
...> """
...> Tabular.to_list_of_lists(ascii_table)
[
  ["name", "dob"],
  ["Malcolm Reynolds", "September 20, 2468"],
  ["Zoe Washburne", "February 15, 2484"]
]
...> Tabular.to_list_of_lists(ascii_table, header: false)
[
  ["Malcolm Reynolds", "September 20, 2468"],
  ["Zoe Washburne", "February 15, 2484"]
]

Without separators:

iex> ascii_table = """
...> |------------------+--------------------|
...> | name             | dob                |
...> |------------------+--------------------|
...> | Malcolm Reynolds | September 20, 2468 |
...> | Zoe Washburne    | February 15, 2484  |
...> |------------------+--------------------|
...> """
...> Tabular.to_list_of_lists(ascii_table)
[
  ["name", "dob"],
  ["Malcolm Reynolds", "September 20, 2468"],
  ["Zoe Washburne", "February 15, 2484"]
]
...> Tabular.to_list_of_lists(ascii_table, header: false)
[
  ["Malcolm Reynolds", "September 20, 2468"],
  ["Zoe Washburne", "February 15, 2484"]
]
Link to this function

to_list_of_lists_no_header(ascii_table) View Source

This function is deprecated. Use to_list_of_lists(table, header: false) instead.

Converts an ascii table to a list of lists, omitting the header row.

Examples

iex> ascii_table = """
...> |---------------+--------------------|
...> | name          | dob                |
...> |---------------+--------------------|
...> | Malcolm       | September 20, 2468 |
...> | Reynolds      |                    |
...> |---------------+--------------------|
...> | Zoe Washburne | February 15, 2484  |
...> |---------------+--------------------|
...> """
...> Tabular.to_list_of_lists_no_header(ascii_table)
[
  ["Malcolm Reynolds", "September 20, 2468"],
  ["Zoe Washburne", "February 15, 2484"]
]

Without separators:

iex> ascii_table = """
...> |------------------+--------------------|
...> | name             | dob                |
...> |------------------+--------------------|
...> | Malcolm Reynolds | September 20, 2468 |
...> | Zoe Washburne    | February 15, 2484  |
...> |------------------+--------------------|
...> """
...> Tabular.to_list_of_lists_no_header(ascii_table)
[
  ["Malcolm Reynolds", "September 20, 2468"],
  ["Zoe Washburne", "February 15, 2484"]
]
Link to this function

to_list_of_maps(ascii_table) View Source

Converts an ascii table to a list of maps.

Examples

iex> ascii_table = """
...> |---------------+--------------------|
...> | name          | dob                |
...> |---------------+--------------------|
...> | Malcolm       | September 20, 2468 |
...> | Reynolds      |                    |
...> |---------------+--------------------|
...> | Zoe Washburne | February 15, 2484  |
...> |---------------+--------------------|
...> """
...> Tabular.to_list_of_maps(ascii_table)
[
  %{dob: "September 20, 2468", name: "Malcolm Reynolds"},
  %{dob: "February 15, 2484", name: "Zoe Washburne"}
]

Without separators:

iex> ascii_table = """
...> |------------------+--------------------|
...> | name             | dob                |
...> |------------------+--------------------|
...> | Malcolm Reynolds | September 20, 2468 |
...> | Zoe Washburne    | February 15, 2484  |
...> |------------------+--------------------|
...> """
...> Tabular.to_list_of_maps(ascii_table)
[
  %{dob: "September 20, 2468", name: "Malcolm Reynolds"},
  %{dob: "February 15, 2484", name: "Zoe Washburne"}
]