Currencies is a collection of all sorts of useful information for every currency in the ISO 4217 standard.
Add currencies
to your list of dependencies in mix.exs
:
def deps do
[{:currencies, "~> 0.5.1"}]
end
After you are done, run mix deps.get
in your shell to fetch and compile Currencies
.
Get all Currencies.
Currencies.all |>
Enum.count
# 162
Gets all currencies matching a currency code or iso numeric code
Currencies.all(["aud", :sgd, 51, %{}])
|> Enum.map(fn(item) ->
case item do
:not_found -> :not_found
item -> item.name
end
end)
# ["Australia Dollar",
# "Singapore Dollar",
# "Armenia Dram",
# :not_found]
Find currency by code.
Currencies.get("AUD") # Currencies.get(:aud) also supported
# %Currencies.Currency{central_bank: %Currencies.CentralBank{name: "Reserve Bank of Australia",
# url: "http://www.rba.gov.au"}, code: "AUD", display: "$",
# minor_unit: %Currencies.MinorUnit{name: "Cent", size: "1/100", symbol: "c"},
# name: "Australia Dollar", nicknames: ["Buck", "Dough"],
# representations: %Currencies.Representations{html: "$",
# unicode_decimal: '$'},
# users: ["Australia", "Christmas Island", "Cocos (Keeling) Islands", "Kiribati",
# "Nauru", "Norfolk Island", "Ashmore and Cartier Islands",
# "Australian Antarctic Territory", "Coral Sea Islands", "Heard Island",
# "McDonald Islands"]}
Find currency by iso numeric code
Currencies.get(36)
# %Currencies.Currency{central_bank: %Currencies.CentralBank{name: "Reserve Bank of Australia",
# url: "http://www.rba.gov.au"}, code: "AUD", display: "$",
# minor_unit: %Currencies.MinorUnit{name: "Cent", size: "1/100", symbol: "c"},
# name: "Australia Dollar", nicknames: ["Buck", "Dough"],
# representations: %Currencies.Representations{html: "$",
# unicode_decimal: '$'},
# users: ["Australia", "Christmas Island", "Cocos (Keeling) Islands", "Kiribati",
# "Nauru", "Norfolk Island", "Ashmore and Cartier Islands",
# "Australian Antarctic Territory", "Coral Sea Islands", "Heard Island",
# "McDonald Islands"]}
Find currency by filtering through the list of currencies.
Currencies.filter(&(String.contains?(&1.name, "Peso"))) |>
Enum.map(&(&1.name))
# ["Argentina Peso", "Chile Peso", "Colombia Peso", "Cuba Convertible Peso", "Cuba Peso",
# "Dominican Republic Peso", "Mexico Peso", "Philippines Peso", "Uruguay Peso"]
Currencies.filter(&(String.contains?(&1.name, "Peso"))) |>
Enum.map(&(&1.name)) |>
Enum.count
# 9
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request