Cldr.Number.Parser.resolve_currency
resolve_currency, go back to Cldr.Number.Parser module for more information.
Specs
resolve_currency(String.t(), Keyword.t()) :: Cldr.Currency.code() | [Cldr.Currency.code() | String.t()] | {:error, {module(), String.t()}}
Resolve a currency from the beginning and/or the end of a string
Arguments
listis any list in which currency names and symbols are expectedoptionsis a keyword list of options
Options
:backendis any module() that includesuse Cldrand therefore is aCldrbackend module(). The default isCldr.default_backend!/0:localeis any valid locale returned byCldr.known_locale_names/1or aCldr.LanguageTagstruct returned byCldr.Locale.new!/2The default isoptions[:backend].get_locale():onlyis anatomor list ofatomsrepresenting 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.:exceptis anatomor list ofatomsrepresenting 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.:fuzzyis a float greater than0.0and less than or equal to1.0which is used as input toString.jaro_distance/2to 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 than0.8in order to reduce false positives.
Returns
An ISO417 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:currentconsiders those currencies that have a:todate of nil and which also is a known ISO4217 currency:historicis the opposite of:current:tenderconsiders currencies that are legal tender:unannotatedconsiders currencies that don't have "(some string)" in their names. These are usually financial instruments.
Examples
iex> Cldr.Number.Parser.resolve_currency("US dollars")
[:USD]
iex> Cldr.Number.Parser.resolve_currency("100 eurosports", fuzzy: 0.75)
[:EUR]
iex> Cldr.Number.Parser.resolve_currency("dollars des États-Unis", locale: "fr")
[:USD]
iex> Cldr.Number.Parser.resolve_currency("not a known currency", locale: "fr")
{:error,
{Cldr.UnknownCurrencyError,
"The currency \"not a known currency\" is unknown or not supported"}}