RedisCluster.Table (redis_cluster v0.8.0)

View Source

A module for formatting lists of lists/tuples into a table-like string representation. Row data is converted to strings, padded for alignment, and formatted with headers. Assumes the header list and all row lists are of the same length.

Summary

Functions

Like rows_to_string/2, but returns iodata instead of a binary. This is more efficient if you are simply logging the output or writing it to a file.

Converts a list of rows (lists or tuples) into a string representation of a table.

Functions

rows_to_iodata(rows, headers)

@spec rows_to_iodata(
  rows :: [[term()]] | [{term()}],
  headers :: [binary()]
) :: [iodata()]

Like rows_to_string/2, but returns iodata instead of a binary. This is more efficient if you are simply logging the output or writing it to a file.

rows_to_string(rows, headers)

@spec rows_to_string(
  rows :: [[term()]] | [{term()}],
  headers :: [binary()]
) :: binary()

Converts a list of rows (lists or tuples) into a string representation of a table.

Example:

iex> rows = [
...>   ["Alice", 30, "Engineer"],
...>   ["Bob", 25, "Designer"]
...> ]
iex> headers = ["Name", "Age", "Occupation"]
iex> RedisCluster.Table.rows_to_string(rows, headers)
"Name  | Age | Occupation\n----- | --- | ----------\nAlice | 30  | Engineer  \nBob   | 25  | Designer  "

The above example will produce a string that looks like this:

Name  | Age | Occupation
----- | --- | ----------
Alice | 30  | Engineer
Bob   | 25  | Designer