Wrapper around Cucumber pickle table data with convenience accessors.
Methods mirror cucumber-ruby's DataTable: raw/1 — [[cell, ...], ...] hashes/1 — [%{header => value}, ...] rows/1 — rows without header rows_hash/1 — first column as key, second as value transpose/1 — swap rows/columns map_headers/2 — rename headers diff!/2 — compare two tables (raises on mismatch)
Summary
Functions
Compare two tables; raise if rows differ, return :ok otherwise.
Treat the first row as headers and return each subsequent row as a map.
Apply a transform function to every value in a named column.
Rename headers using a map of old -> new or a 1-arity function.
Wrap a list of rows in a DataTable.
Return the raw rows list.
Return rows without the header.
Treat each row as a key/value pair (first column = key, second = value).
Like hashes/1 but converts header keys to atoms.
Swap rows and columns.
Raise if col_name is not among the header row; return :ok otherwise.
Raise if any row's length differs from width; return :ok otherwise.
Types
@type t() :: %Cucumberex.DataTable{rows: [[String.t()]]}
Functions
Compare two tables; raise if rows differ, return :ok otherwise.
Examples
iex> a = Cucumberex.DataTable.new([["h"], ["1"]])
iex> Cucumberex.DataTable.diff!(a, a)
:ok
Treat the first row as headers and return each subsequent row as a map.
Examples
iex> Cucumberex.DataTable.new([["name", "age"], ["alice", "30"]])
...> |> Cucumberex.DataTable.hashes()
[%{"name" => "alice", "age" => "30"}]
iex> Cucumberex.DataTable.new([]) |> Cucumberex.DataTable.hashes()
[]
Apply a transform function to every value in a named column.
Examples
iex> Cucumberex.DataTable.new([["n", "v"], ["a", "1"], ["b", "2"]])
...> |> Cucumberex.DataTable.map_column("v", &String.to_integer/1)
...> |> Cucumberex.DataTable.raw()
[["n", "v"], ["a", 1], ["b", 2]]
Rename headers using a map of old -> new or a 1-arity function.
Examples
iex> Cucumberex.DataTable.new([["full name"], ["alice"]])
...> |> Cucumberex.DataTable.map_headers(%{"full name" => "name"})
...> |> Cucumberex.DataTable.raw()
[["name"], ["alice"]]
iex> Cucumberex.DataTable.new([["name"], ["alice"]])
...> |> Cucumberex.DataTable.map_headers(&String.upcase/1)
...> |> Cucumberex.DataTable.raw()
[["NAME"], ["alice"]]
Wrap a list of rows in a DataTable.
Examples
iex> Cucumberex.DataTable.new([["a", "b"], ["1", "2"]]).rows
[["a", "b"], ["1", "2"]]
Return the raw rows list.
Examples
iex> Cucumberex.DataTable.new([["a"], ["1"]]) |> Cucumberex.DataTable.raw()
[["a"], ["1"]]
Return rows without the header.
Examples
iex> Cucumberex.DataTable.new([["h"], ["1"], ["2"]]) |> Cucumberex.DataTable.rows()
[["1"], ["2"]]
iex> Cucumberex.DataTable.new([]) |> Cucumberex.DataTable.rows()
[]
Treat each row as a key/value pair (first column = key, second = value).
Examples
iex> Cucumberex.DataTable.new([["name", "alice"], ["age", "30"]])
...> |> Cucumberex.DataTable.rows_hash()
%{"name" => "alice", "age" => "30"}
Like hashes/1 but converts header keys to atoms.
Only call this when headers are known, bounded values (e.g. fixture table headers
that match struct fields). Avoid with arbitrary user-supplied table headers —
use hashes/1 instead to prevent unbounded atom creation.
Examples
iex> Cucumberex.DataTable.new([["name"], ["alice"]])
...> |> Cucumberex.DataTable.symbolic_hashes()
[%{name: "alice"}]
Swap rows and columns.
Examples
iex> Cucumberex.DataTable.new([["a", "b"], ["1", "2"]])
...> |> Cucumberex.DataTable.transpose()
...> |> Cucumberex.DataTable.raw()
[["a", "1"], ["b", "2"]]
Raise if col_name is not among the header row; return :ok otherwise.
Examples
iex> Cucumberex.DataTable.new([["name", "age"]]) |> Cucumberex.DataTable.verify_column!("name")
:ok
Raise if any row's length differs from width; return :ok otherwise.
Examples
iex> Cucumberex.DataTable.new([["a", "b"], ["1", "2"]])
...> |> Cucumberex.DataTable.verify_table_width!(2)
:ok