alexrabarts / iso_country_codes Goto Github PK
View Code? Open in Web Editor NEWA Ruby library that provides ISO 3166-1 country codes/names and ISO 4217 currencies
Home Page: http://github.com/alexrabarts/iso-country-codes
A Ruby library that provides ISO 3166-1 country codes/names and ISO 4217 currencies
Home Page: http://github.com/alexrabarts/iso-country-codes
Shouldn't the Bahamas calling code be +1242
instead of +242
?
I think it's the same with all the american islands (american samoa +684
, ...)
Hi,
I was interested in evolving this into containing the country state/provinces codes for ISO 3166-2. For example the ISO 3166-2:EC for Ecuador or ISO 3166-2:BR for Brazil.
Before I fork this, are there any comments or remarks or even guiding as to what pattern, format to follow?
Regards,
Taiwan is not a country. You should remove it from your readme file
Hi! I would make sense to support the ISO 3166-2 for region support in this gem?
I was looking for something that can group the ISO codes for Countries, Regions and Currencies and this seems to be a good match.
The name's for the states of Saint Lucia are all nil. See below.
[pry(main)> c.data["name"]
=> "Saint Lucia"
[pry(main)> c.states.map { |state| state.last["name"] }
=> [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
["01",
#<struct ISO3166::Subdivision
name=nil,
code=nil,
unofficial_names=nil,
geo=nil,
translations=
{"ar"=>"حي أنس لا راي",
"bn"=>"আন্স লা রায়ে কোয়ার্টার",
"da"=>"Anse la Raye Quarter",
"de"=>"Anse-la-Raye",
"el"=>"Άνς λα Ράιγ",
"en"=>"Anse la Raye",
"es"=>"Anse La Raye",
"eu"=>"Anse la Raye auzoa",
"fa"=>"بخش آنسه لا ریه",
"fi"=>"Anse-la-Raye",
"fr"=>"District d’Anse-la-Raye",
"gu"=>"એન્સે લા રેય ક્વાર્ટર",
"hi"=>"एंस ला राए क्वार्टर",
"id"=>"Anse la Raye Quarter",
"it"=>"quartiere di Anse-la-Raye",
"ja"=>"アンス・ラ・レイ地区",
"kn"=>"ಆನ್ಸೆ ಲಾ ರೇಯ್ ಕ್ವಾರ್ಟರ್",
"ko"=>"앙스라레 구",
"lt"=>"Ans Lavua",
"mr"=>"अं. ला राय क्वार्टर",
"ms"=>"Anse la Raye Quarter",
"nb"=>"Anse la Raye Quarter",
"nl"=>"Anse-la-Raye",
"pl"=>"Anse la Raye",
"pt"=>"Anse-La-Raye",
"ru"=>"Анс-Лавуа",
"si"=>"අන්සේ ලා රයේ කාර්ටර්",
"sv"=>"Anse la Raye Quarter",
"ta"=>"அன்ஸே லா ரே குஆர்டெர்",
"te"=>"ఆన్స్ లా రే",
"th"=>"แอนซี่ ลา เรย์ ควอเตอร์",
"tr"=>"Anse la Raye (şehir)",
"ur"=>"انسے لا رائے کوارٹر",
"vi"=>"Anse la Raye",
"zh"=>"昂斯拉雷區"},
comments=nil>]
Good day, I'm using your library and after release of 0.7.2 version
IsoCountryCodes.for_select
returns
["Virgin Islands (U.S.)", "VI"],
["Wallis and Futuna", "WF"],
["Western Sahara", "EH"],
["Yemen", "YE"],
["Zambia", "ZM"],
["Zimbabwe", "ZW"],
[nil, nil]]
nil values at the end.
Reverted back to 0.7.1 and this problem has gone. Can someone else prove it? Is it a valid output?
IsoCountryCodes.search_by_name('')
returns not empty list as expected =(
Bing's api returns "Laos" as the country name of Lao People's Democratic Republic so this gem cannot be able to search by 'Laos'.
Location: http://schemas.microsoft.com/search/local/ws/rest/v1
I had to add Kosovo and rename "Macedonia (the former Yugoslav Republic of)" to "North Macedonia". I fixed my issue by adding this:
class XXK < IsoCountryCodes::Code
self.numeric = nil
self.name = %q{Kosovo}
self.alpha2 = %q{XK}
self.alpha3 = %q{XXK}
self.iban = 'XK'
self.main_currency = 'EUR'
self.continent = 'EU'
self.calling = '+383'
end
IsoCountryCodes::Code::MKD.module_eval do
self.name = %q{North Macedonia}
end
Because I use the gem for Ruby on Rails I added the code to: config/initializers/adjust_iso_country_codes.rb.
Kosovo appears on the last place. Where can I add .sort_by to resort all the countries?
The ISO3166 data is copyright by ISO; you can purchase it here:
http://www.iso.org/iso/publications_and_e-products/databases.htm#PUB100050.
The 2-character codes and mapping to French and English names are free for internal and non-commercial use, but the numeric codes (database IDs as they call them) are only available to those who have purchased them.
You probably need to modify your copyright message to reflect that.
Hi @alexrabarts ,
when you search by name:
IsoCountryCodes.search_by_name('Cocos (Keeling) Islands')[0].alpha2
exception is thrown
IsoCountryCodes::UnknownCodeError: No ISO 3166-1 codes could be found searching with name 'Cocos (Keeling) Islands'.
Name is defined in this line
https://github.com/alexrabarts/iso_country_codes/blob/master/lib/iso_country_codes/iso_3166_1.rb#L259
Regards, Karlo.
@alexrabarts thanks for your work on this. I'm using it in a production app!
Are you still maintaining this project? I'd be happy to step up to the plate and implement this myself if you're still around and merging pool requests.
I'm using the gem in a save callback on a model in conjunction with a geocoding service that is returning country codes. I convert the country code to the country name using iso_country_codes. It makes me nervous that the third party service could return a new or invalid country code and prevent the model from saving. So, I'm doing something like this:
user.country = begin; IsoCountryCodes.find(geo.country).name; rescue; geo.country; end;
It'd be handy if there was a configuration option to return whatever was passed to the find
method if no country is found instead of raising an error.
You have the wrong currency code for South Korea.. it should be KRW, not KPW (that is North Korean Won) :)
Would it be possible to have this work? What's the policy on alternative spellings for country names? Stripe currently gives the old name and crashes the search.
https://en.wikipedia.org/wiki/ISO_3166-2:MO
pry(main)> IsoCountryCodes.search_by_name('Macao')
=> [#<IsoCountryCodes::Code::MAC:0x007ffb84191360>]
pry(main)> IsoCountryCodes.search_by_name('Macau')
IsoCountryCodes::UnknownCodeError: No ISO 3166-1 codes could be found searching with name 'Macau'.
from /Users/nruth/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/iso_country_codes-0.6.1/lib/iso_country_codes/iso_country_codes.rb:14:in `block in singleton class'
IsoCountryCodes.search_by_name("USA") -> nothing
IsoCountryCodes.search_by_name("US") -> bunch of things, not US
IsoCountryCodes.search_by_name("United states") -> works! :)
Maybe exactly as designed. Would you like a PR?
Kosovo has recently become recognized as a country. It appears the wiki page you are scraping has not updated, and the timeline is uncertain on when that may happen. Would there be an objection to submitting a PR that injects Kosovo manually into the list? There appears to be a recommendation to use "XK" at https://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/ .
While Cyprus is closest to Asia Minor, it still belongs to Europe. Cyprus is also a member of the European union, so it's continent should be Europe.
https://github.com/alexrabarts/iso_country_codes/blob/master/lib/iso_country_codes/continent.rb#L162
What I did:
gem install 'iso_country_codes
irb
require 'iso_country_codes
IsoCountryCodes.search_by_name('Belgie')
What I expected:
BE
What I got:
❯ irb
2.4.0 :001 > require 'iso_country_codes'
=> true
2.4.0 :002 > IsoCountryCodes.search_by_name('Belgie')
NoMethodError: undefined method `to_set' for ["AFGHANISTAN"]:Array
Did you mean? to_s
from /X/.rvm/gems/ruby-2.4.0/gems/iso_country_codes-0.7.8/lib/iso_country_codes/iso_country_codes.rb:94:in `word_set'
from /X/.rvm/gems/ruby-2.4.0/gems/iso_country_codes-0.7.8/lib/iso_country_codes/iso_country_codes.rb:44:in `block in search_by_name'
from /X/.rvm/gems/ruby-2.4.0/gems/iso_country_codes-0.7.8/lib/iso_country_codes/iso_country_codes.rb:44:in `select'
from /X/.rvm/gems/ruby-2.4.0/gems/iso_country_codes-0.7.8/lib/iso_country_codes/iso_country_codes.rb:44:in `search_by_name'
from (irb):2
from /X/.rvm/rubies/ruby-2.4.0/bin/irb:11:in `<main>'
Would it be possible to change iso_4217.rb and iso_3166_1.rb such that the values are read in from a yml file? Doing that and allowing any key for the property names (using method_missing or defining methods based on the attribute keys that are read in from the yaml file - instead of hard-coded method names in the ruby class) will allow the following:
The yml file could then be "externalized" to the consumer (you will need to provide a way for the gem consumer to specify a custom yml file) - ie they can take the default, add new attributes (for eg, in my case, I would like a "flag_sprite_class", "phone_code", "enabled"). Extending the gem will be super-easy in this case! What do you think?
There are few countries that spec across multiple continents. I would expect for those countries to receive a list of continent codes as their continent, while the library sticks to only one of those.
See details in https://ipfs.io/ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco/wiki/List_of_transcontinental_countries.html
Examples of those are Russia, Egypt, Turkey.
I have a tool that returning country names to me, which I think pass to iso_country_codes. In one case, it returned "Republic of Korea", and iso_country_codes couldn't find it and returned an error. This got me digging, and I found this is because the "Republic of" part of the name is parenthetical in https://github.com/alexrabarts/iso_country_codes/blob/master/lib/iso_country_codes/iso_3166_1.rb
I'm not claiming this is an error or bug, because when it comes to naming things, its never easy. It did lead me look at other records in the file, and I noticed that sometimes parenthesis are used for parts of the country name, other times its a comma that separates the parts. I'm wondering if there is a reason for the difference, or if its an inconsistency? If its an inconsistency, I wouldn't mind opening a PR for it.
Also, for these cases, would it be feasible for iso_country_codes to do a comparison between the input, and a version of the country name where the parenthesis were removed and order flipped? Again, I wouldn't be opposed to doing the leg work on the PR, but since I don't know the library very well, I wanted to find out if there may be other technical or non-technical reasons that this would be a bad idea before I started trying to code it up.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.