# `Localize.Number.PluralRule.Range`
[🔗](https://github.com/elixir-localize/localize/blob/v1.2.0/lib/localize/number/plural_rules/range.ex#L1)

Plural category selection for numeric ranges.

Implements the [TR35 plural ranges](https://unicode.org/reports/tr35/tr35-numbers.html#Plural_Ranges) rules: the plural category of a range like "1–2 days" is derived from the categories of its endpoints using per-language range rules from the CLDR supplemental data. The primary functions are `plural_rule/3` for endpoint categories and `plural_rule_for/3` for endpoint numbers.

# `plural_rule`

```elixir
@spec plural_rule(atom(), atom(), atom() | String.t() | Localize.LanguageTag.t()) ::
  {:ok, atom()} | {:error, Exception.t()}
```

Returns the plural category for a range given the categories of its endpoints.

### Arguments

* `start_category` is the plural category of the range start.

* `end_category` is the plural category of the range end.

* `locale` is a locale identifier atom, string, or a `t:Localize.LanguageTag.t/0` struct.

### Returns

* `{:ok, category}` where `category` is one of `:zero`, `:one`, `:two`, `:few`, `:many`, or `:other`.

* `{:error, exception}` if the locale is invalid.

### Examples

    iex> Localize.Number.PluralRule.Range.plural_rule(:one, :other, "fr")
    {:ok, :other}

    iex> Localize.Number.PluralRule.Range.plural_rule(:one, :one, "fr")
    {:ok, :one}

# `plural_rule_for`

```elixir
@spec plural_rule_for(
  number() | Decimal.t(),
  number() | Decimal.t(),
  atom() | String.t() | Localize.LanguageTag.t()
) :: {:ok, atom()} | {:error, Exception.t()}
```

Returns the plural category for a range given the numbers of its endpoints.

The endpoint categories are selected with the locale's cardinal plural rules, then combined with `plural_rule/3`.

### Arguments

* `start_number` is the start of the range (integer, float, or Decimal).

* `end_number` is the end of the range.

* `locale` is a locale identifier atom, string, or a `t:Localize.LanguageTag.t/0` struct.

### Returns

* `{:ok, category}` where `category` is one of `:zero`, `:one`, `:two`, `:few`, `:many`, or `:other`.

* `{:error, exception}` if the locale is invalid.

### Examples

    iex> Localize.Number.PluralRule.Range.plural_rule_for(0, 1, "fr")
    {:ok, :one}

    iex> Localize.Number.PluralRule.Range.plural_rule_for(1, 2, "fr")
    {:ok, :other}

---

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