# `Spectre.Rule`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/types/rule.ex#L1)

Declarative routing rule compiled from `Spectre.Agent` DSL.

Rules are internal domain data. They normalize DSL options such as regexes,
examples, checks, and handler declarations before any router plug sees them.

    rule =
      Spectre.Rule.new(%{
        label: :help,
        flow: :support,
        regex: ~r/^help$/i,
        handler: {:reply, :help, []}
      })

# `handler`

```elixir
@type handler() ::
  {:ask, term(), keyword()}
  | {:reason, term(), keyword()}
  | {:act, term(), keyword()}
  | {:run, atom(), keyword()}
  | {:work, module(), keyword()}
  | {:reply, term(), keyword()}
  | {:action, Spectre.Action.ref(), keyword()}
  | {:operation, term(), keyword()}
  | {:server, {[atom()], atom()}, keyword()}
```

# `t`

```elixir
@type t() :: %Spectre.Rule{
  bag: [String.t()],
  cache: boolean(),
  checks: [{atom() | String.t(), term()}],
  constraints: [Spectre.Flow.Constraint.t()],
  definition_injections: [Spectre.Prompt.Operation.t()],
  embedding: [String.t()],
  flow: atom() | nil,
  flow_path: [atom()],
  global?: boolean(),
  handler: handler(),
  injections: [Spectre.Prompt.Operation.t()],
  jaro: [String.t()],
  label: atom(),
  learn: boolean(),
  opts: keyword(),
  owner: module() | nil,
  regex: [Regex.t()],
  scope: Spectre.Definition.scope(),
  via: [atom()]
}
```

# `checks_match?`

```elixir
@spec checks_match?(t(), Spectre.Input.t()) :: boolean()
```

Returns true when all checks pass against an input.

    Spectre.Rule.checks_match?(rule, input)

# `match?`

```elixir
@spec match?(t(), String.t()) :: boolean()
```

Returns true when any deterministic regex on the rule matches the text.

    Spectre.Rule.match?(rule, "hello")

# `new`

```elixir
@spec new(map()) :: t()
```

Builds a normalized routing rule from DSL metadata.

    %Spectre.Rule{} = Spectre.Rule.new(%{label: :hello, regex: ~r/hello/})

---

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