Skip to content

Instantly share code, notes, and snippets.

@dacer
Last active March 3, 2017 06:45
Show Gist options
  • Save dacer/4e61507ec2d51975e771654a45b4919a to your computer and use it in GitHub Desktop.
Save dacer/4e61507ec2d51975e771654a45b4919a to your computer and use it in GitHub Desktop.
Convert ISO-3166 Country alpha-2 to full name
#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