# `Filtrex.Condition`
[🔗](https://github.com/rcdilorenzo/filtrex/blob/main/lib/filtrex/condition.ex#L1)

`Filtrex.Condition` is an abstract module for parsing conditions.
To implement your own condition, add `use Filtrex.Condition` in your module and implement the three callbacks:

  * `parse/2` - produce a condition struct from a configuration and attributes
  * `type/0` - the description of the condition that must match the underscore version of the module's last namespace
  * `comparators/0` - the list of used query comparators for parsing params

# `comparators`

```elixir
@callback comparators() :: [String.t()]
```

# `parse`

```elixir
@callback parse(Filtrex.Type.Config.t(), %{
  inverse: boolean(),
  column: String.t(),
  value: any(),
  comparator: String.t()
}) :: {:ok, any()} | {:error, any()}
```

# `type`

```elixir
@callback type() :: Atom.t()
```

# `condition_modules`

List out the available condition modules

# `param_key_type`

Parses a params key into the condition type, column, and comparator

# `parse`

Parses a condition by dynamically delegating to modules

It delegates based on the type field of the options map (e.g. `Filtrex.Condition.Text` for the type `"text"`).
Example Input:
config:
```
Filtrex.Condition.parse([
  %Filtrex.Type.Config{type: :text, keys: ~w(title comments)}
], %{
  type: string,
  column: string,
  comparator: string,
  value: string,
  inverse: boolean                   # inverts the comparator logic
})
```

# `parse_error`

```elixir
@spec parse_error(any(), Atom.t(), Atom.t()) :: String.t()
```

Generates an error description for a generic parse error

# `parse_value_type_error`

```elixir
@spec parse_value_type_error(any(), Atom.t()) :: String.t()
```

Generates an error description for a parse error resulting from an invalid value type

# `validate_comparator`

```elixir
@spec validate_comparator(atom(), binary(), List.t()) ::
  {:ok, binary()} | {:error, binary()}
```

Helper method to validate that a comparator is in list

# `validate_in`

```elixir
@spec validate_in(any(), List.t()) :: nil | any()
```

Helper method to validate whether a value is in a list

# `validate_is_binary`

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

Helper method to validate whether a value is a binary

---

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