# `Spectre.Router.Candidate`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/router/candidate.ex#L1)

A single routing signal produced by a router evidence provider.

Candidates let router plugs report what they know without deciding the final
route. The arbitrator can then compare hard regex matches, classifier scores,
semantic cache hits, and other evidence with one common shape.

# `strength`

```elixir
@type strength() :: :hard | :strong | :medium | :weak
```

# `t`

```elixir
@type t() :: %Spectre.Router.Candidate{
  accepted?: boolean(),
  flow: atom() | nil,
  handler: Spectre.Rule.handler() | nil,
  label: atom() | nil,
  margin: float() | nil,
  matched: term(),
  metadata: map() | nil,
  owner: module() | nil,
  provider: atom(),
  raw: term(),
  rule: Spectre.Rule.t() | nil,
  scope: Spectre.Definition.scope() | nil,
  score: float() | nil,
  strength: strength(),
  terminal?: boolean()
}
```

# `from_result`

```elixir
@spec from_result(
  map() | Spectre.Route.t(),
  Spectre.Rule.t() | nil,
  atom(),
  keyword()
) :: t()
```

Builds a candidate from an adapter result map.

    candidate =
      Spectre.Router.Candidate.from_result(%{label: :help, confidence: 0.94}, rule, :classifier)

# `from_rule`

```elixir
@spec from_rule(Spectre.Rule.t(), atom(), String.t(), keyword()) :: t()
```

Builds a candidate from a compiled rule match.

    candidate = Spectre.Router.Candidate.from_rule(rule, :regex, input.text)

# `new`

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

Builds a candidate from normalized attributes.

Unknown keys are ignored. Prefer `from_rule/4` or `from_result/4` at adapter
boundaries because they derive rule ownership, evidence strength, and score
fields consistently.

    candidate =
      Spectre.Router.Candidate.new(%{
        label: :HELP,
        provider: :custom,
        score: 0.9,
        accepted?: true
      })

# `to_route`

```elixir
@spec to_route(t(), [atom()]) :: Spectre.Route.t()
```

Converts the winning candidate into a Spectre route.

    route = Spectre.Router.Candidate.to_route(candidate, [:help, :fallback])

---

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