# `Cldr.Rbnf`
[🔗](https://github.com/elixir-cldr/cldr_numbers/blob/v2.38.1/lib/cldr/number/rbnf.ex#L1)

Functions to implement Rules Based Number Formatting (rbnf)

During compilation RBNF rules are extracted and generated
as function bodies by `Cldr.Rbnf.Ordinal`, `Cldr.Rbnf.Cardinal`
and `Cldr.Rbnf.NumberSystem`.

The functions in this module would not normally be of common
use outside of supporting the compilation phase.

# `for_locale`

```elixir
@spec for_locale(Cldr.LanguageTag.t()) ::
  {:ok, map()} | {:error, {module(), String.t()}}
```

Returns {:ok, rbnf_rules} for a `locale` or `{:error, {Cldr.NoRbnf, info}}`

* `locale` is any `t:Cldr.LanguageTag`

This function reads the raw locale definition and therefore
should *not* be called at runtime.

# `for_locale`

```elixir
@spec for_locale(Cldr.Locale.locale_name() | Cldr.LanguageTag.t(), Cldr.backend()) ::
  {:ok, map()} | {:error, {module(), String.t()}}
```

Returns {:ok, rbnf_rules} for a `locale` or `{:error, {Cldr.NoRbnf, info}}`

* `locale` is any locale name returned by `Cldr.Rbnf.known_locale_names/1`

* `backend` is any module that includes `use Cldr` and therefore
  is a `Cldr` backend module

# `for_locale!`

Returns rbnf_rules for a `locale` or raises an exception if
there are no rules.

* `locale` is any `Cldr.LanguageTag`

* `backend` is any module that includes `use Cldr` and therefore
  is a `Cldr` backend module

# `for_locale!`

Returns rbnf_rules for a `locale` and `backend` or raises an exception if
there are no rules.

* `locale` is any locale name returned by `Cldr.Rbnf.known_locale_names/1`

* `backend` is any module that includes `use Cldr` and therefore
  is a `Cldr` backend module

# `known_locale_names`

Returns the list of locales that that have RBNF defined

This list is the set of known locales for which
there are rbnf rules defined.

Delegates to `Cldr.known_rbnf_locale_names/1`

# `rbnf_locale_error`

# `rbnf_rule_error`

# `rule_names_for_locale`

```elixir
@spec rule_names_for_locale(Cldr.LanguageTag.t()) ::
  {:ok, [atom()]} | {:error, {module(), String.t()}}
```

Returns the list of RBNF rules for a locale.

A rule name can be used as the `:format` parameter
in `Cldr.Number.to_string/3`.

## Arguments

* `locale` is any `Cldr.LanguageTag.t()`

## Returns

* `{:ok, [list_of_rule_names_as_atoms]}` or

* `{:error, {exception, reason}}`

## Examples

    iex> Cldr.Rbnf.rule_names_for_locale "zh"
    {:ok,
     [:spellout_cardinal_alternate2, :spellout_ordinal, :spellout_cardinal,
      :spellout_cardinal_financial, :spellout_numbering, :spellout_numbering_days,
      :spellout_numbering_year, :digits_ordinal]}

    iex> Cldr.Rbnf.rule_names_for_locale "fp"
    {:error, {Cldr.InvalidLanguageError, "The language "fp" is invalid"}}

# `rule_names_for_locale`

# `rule_names_for_locale!`

```elixir
@spec rule_names_for_locale!(Cldr.LanguageTag.t()) :: [atom()] | no_return()
```

Returns the list of RBNF rules for a locale.

A rule name can be used as the `:format` parameter
in `Cldr.Number.to_string/3`.

## Arguments

* `locale` is any `Cldr.LanguageTag.t()`

## Returns

* `[list_of_rule_names_as_atoms]`, or

* raises an exception

## Examples

    iex> Cldr.Rbnf.rule_names_for_locale! "zh"
    [:spellout_cardinal_alternate2, :spellout_ordinal, :spellout_cardinal,
     :spellout_cardinal_financial, :spellout_numbering, :spellout_numbering_days,
     :spellout_numbering_year, :digits_ordinal]

---

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