# `AncestryEx.Format`
[🔗](https://github.com/rocket4ce/ancestry_ex/blob/v0.1.0/lib/ancestry_ex/format.ex#L1)

Encoding of the ancestry column.

Two formats are supported, both compatible with the Ruby `ancestry` gem:

  * `:materialized_path2` (default, recommended) - roots store `"/"`, a node
    whose ancestors are 1 and 2 stores `"/1/2/"`. The column can be `NOT NULL`
    and descendant lookups are a single `LIKE 'prefix%'`.

  * `:materialized_path` - roots store `NULL`, a node whose ancestors are 1 and
    2 stores `"1/2"`. Use it when migrating a table managed by the gem's legacy
    default format.

# `t`

```elixir
@type t() :: :materialized_path | :materialized_path2
```

# `child_ancestry`

```elixir
@spec child_ancestry(t(), String.t() | nil, term()) :: String.t()
```

Ancestry value of the children of a node with the given `ancestry` and `id`.

# `depth`

```elixir
@spec depth(t(), String.t() | nil) :: non_neg_integer()
```

Depth of a node with the given ancestry value (roots have depth 0).

# `generate`

```elixir
@spec generate(t(), [term()]) :: String.t() | nil
```

Builds an ancestry value from a list of ancestor ids, root first.

# `parse`

```elixir
@spec parse(t(), String.t() | nil) :: [String.t()]
```

Splits an ancestry value into its id segments (as strings), root first.

# `root_value`

```elixir
@spec root_value(t()) :: String.t() | nil
```

Value stored in the ancestry column of a root node.

# `valid?`

```elixir
@spec valid?(t(), String.t() | nil, Ecto.Type.t()) :: boolean()
```

Returns true if `ancestry` is well formed for the format and primary key type.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
