Cldr.Number.Parser.resolve_currencies

You're seeing just the function resolve_currencies, go back to Cldr.Number.Parser module for more information.
Link to this function

resolve_currencies(list, options \\ [])

View Source

Specs

resolve_currencies([String.t(), ...], Keyword.t()) :: [
  Cldr.Currency.code() | String.t()
]

Resolve curencies from strings within a list.

Currencies can be identified at the beginning and/or the end of a string.

Arguments

  • list is any list in which currency names and symbols are expected

  • options is a keyword list of options

Options

  • :backend is any module() that includes use Cldr and therefore is a Cldr backend module(). The default is Cldr.default_backend!/0

  • :locale is any valid locale returned by Cldr.known_locale_names/1 or a t:Cldr.LanguageTag struct returned by Cldr.Locale.new!/2 The default is options[:backend].get_locale()

  • :only is an atom or list of atoms representing the currencies or currency types to be considered for a match. The equates to a list of acceptable currencies for parsing. See the notes below for currency types.

  • :except is an atom or list of atoms representing the currencies or currency types to be not considered for a match. This equates to a list of unacceptable currencies for parsing. See the notes below for currency types.

  • :fuzzy is a float greater than 0.0 and less than or equal to 1.0 which is used as input to String.jaro_distance/2 to determine is the provided currency string is close enough to a known currency string for it to identify definitively a currency code. It is recommended to use numbers greater than 0.8 in order to reduce false positives.

Returns

  • An ISO4217 currency code as an atom or

  • {:error, {exception, message}}

Notes

The :only and :except options accept a list of currency codes and/or currency types. The following types are recognised.

If both :only and :except are specified, the :except entries take priority - that means any entries in :except are removed from the :only entries.

  • :all, the default, considers all currencies

  • :current considers those currencies that have a :to date of nil and which also is a known ISO4217 currency

  • :historic is the opposite of :current

  • :tender considers currencies that are legal tender

  • :unannotated considers currencies that don't have "(some string)" in their names. These are usually financial instruments.

Examples

iex> Cldr.Number.Parser.scan("100 US dollars")
...> |> Cldr.Number.Parser.resolve_currencies
[100, :USD]

iex> Cldr.Number.Parser.scan("100 eurosports")
...> |> Cldr.Number.Parser.resolve_currencies(fuzzy: 0.8)
[100, :EUR]

iex> Cldr.Number.Parser.scan("100 dollars des États-Unis")
...> |> Cldr.Number.Parser.resolve_currencies(locale: "fr")
[100, :USD]