Masu.Filter (Masu v0.1.0)

Copy Markdown View Source

A condition on a column that a row must meet to be in the grid.

op is one of:

  • :eq and :neq: equal, or not, to value;
  • :contains, :not_contains, :starts_with and :ends_with: for text, without case;
  • :gt, :gte, :lt and :lte: greater or less than value;
  • :between: from the first to the second value of a two-item list, both included;
  • :in: one of the values of a list;
  • :is_nil and :not_nil: no value, or any value (with no value).

The value is read for the column's type (see Masu.Column): a date column takes "2026-10-17" or a Date, a number column "12.5" or 12.5.

Summary

Functions

Checks a filter against the grid's columns and reads its value for the column's type. Returns the filter with the value read, or an error that says why: no such column, a column that does not filter, an operator that is not for its type, or a value it cannot read.

Whether a value meets the filter, as Masu.Source.List checks it. The filter's value must already be read (cast/2).

A filter on the column with key.

The operators of a filter.

The operators of a filter on a column of type: those of text only for text and enums.

Types

op()

@type op() ::
  :eq
  | :neq
  | :contains
  | :not_contains
  | :starts_with
  | :ends_with
  | :gt
  | :gte
  | :lt
  | :lte
  | :between
  | :in
  | :is_nil
  | :not_nil

t()

@type t() :: %Masu.Filter{key: String.t(), op: op(), value: term()}

Functions

cast(filter, columns)

@spec cast(t(), [Masu.Column.t()]) :: {:ok, t()} | {:error, String.t()}

Checks a filter against the grid's columns and reads its value for the column's type. Returns the filter with the value read, or an error that says why: no such column, a column that does not filter, an operator that is not for its type, or a value it cannot read.

match?(filter, value)

@spec match?(t(), term()) :: boolean()

Whether a value meets the filter, as Masu.Source.List checks it. The filter's value must already be read (cast/2).

new(key, op, value \\ nil)

@spec new(String.t() | atom(), op(), term()) :: t()

A filter on the column with key.

ops()

@spec ops() :: [op()]

The operators of a filter.

ops(type)

@spec ops(Masu.Column.type()) :: [op()]

The operators of a filter on a column of type: those of text only for text and enums.