-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Currency database should know if a currency is still in use #77
Comments
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'json'
require 'open-uri'
require 'pry'
require 'money'
LOCALE = 'en-US-POSIX'
local_file = File.read('config/currency_iso.json')
local_hash = JSON.parse(local_file)
local_version = local_hash.delete('_version')
currencies_uri = URI.parse("https://raw.githubusercontent.com/unicode-cldr/cldr-numbers-modern/master/main/#{LOCALE}/currencies.json")
currencies = JSON.parse(File.read(currencies_uri.open))
currency_data = URI.parse('https://raw.githubusercontent.com/unicode-cldr/cldr-core/master/supplemental/currencyData.json')
currency_data = JSON.parse(File.read(currency_data.open))
data = currencies['main'][LOCALE]["numbers"]["currencies"].merge(currency_data["supplemental"]["currencyData"]["fractions"])
data.each do |iso, api_data|
unless currency = Money::Currency.find(iso)
next #p "#{iso}: Missing currency"
end
api_name = api_data['displayName']&.gsub(/\(.*\)/, '')
# p "#{iso}: {name:[#{currency.name}, #{api_name}]}" unless currency.name == api_name
unless currency.minor_units.to_i == (api_data["_digits"] || 2).to_i
p "#{iso}: {minor_units:[#{currency.minor_units}, #{(api_data["_digits"] || 2).to_i}]}"
end
end gives this list of incorrect currency minor units [our value, unicode-cldr value]
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For example 'NLG' is the ISO4217 code for the Dutch guilder that got replaced by the Euro in 2002. The euro was introduced as legal tender in 1999.
Use case: generating a list of valid and currently in use ISO codes to show in a dropdown for the user to select, while having a database validation on all valid currency codes.
The Unicode CLDR has this data:
The text was updated successfully, but these errors were encountered: