Last active
March 3, 2017 06:45
-
-
Save dacer/4e61507ec2d51975e771654a45b4919a to your computer and use it in GitHub Desktop.
Convert ISO-3166 Country alpha-2 to full name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Thanks for https://github.com/lukes/ISO-3166-Countries-with-Regional-Codes | |
require 'json' | |
require 'rest-client' | |
TEST_LIST = "AT, BE, BG, CY, CZ, DE, DK, EE, ES, FI, FR, GB, GR, HU, IE, IT, LT, LU, LV, MT, NL, PL, PT, RO, SE, SI, SK, US".split(", ") | |
JSON_URL = 'https://github.com/lukes/ISO-3166-Countries-with-Regional-Codes/raw/master/slim-2/slim-2.json' | |
response = RestClient.get(JSON_URL) | |
json = JSON.parse(response) | |
puts json.select { |j| TEST_LIST.include?(j["alpha-2"]) }.map { |j| j["name"]}.join("\n") | |
=begin | |
OUTPUT: | |
Austria | |
Belgium | |
Bulgaria | |
Cyprus | |
Czech Republic | |
Denmark | |
Estonia | |
Finland | |
France | |
Germany | |
Greece | |
Hungary | |
Ireland | |
Italy | |
Latvia | |
Lithuania | |
Luxembourg | |
Malta | |
Netherlands | |
Poland | |
Portugal | |
Romania | |
Slovakia | |
Slovenia | |
Spain | |
Sweden | |
United Kingdom of Great Britain and Northern Ireland | |
United States of America | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment