Skip to content

Instantly share code, notes, and snippets.

@Andrzej
Created October 11, 2010 21:57
Show Gist options
  • Save Andrzej/621308 to your computer and use it in GitHub Desktop.
Save Andrzej/621308 to your computer and use it in GitHub Desktop.
Utility to convert country name into continent name
AFRICA=[
"Algeria",
"Angola",
"Benin",
"Botswana",
"Burkina",
"Burkina Faso",
"Burundi",
"Cameroon",
"Cape Verde",
"Central African Republic",
"Chad",
"Comoros",
"Congo",
"Congo (Dem. Rep.)",
"Democratic Republic Congo",
"Côte d'Ivoire",
"Cote d'Ivoire",
"Djibouti",
"Egypt",
"Equatorial Guinea",
"Eritrea",
"Ethiopia",
"Gabon",
"Gambia",
"Ghana",
"Guinea",
"Guinea-Bissau",
"Ivory Coast",
"Kenya",
"Lesotho",
"Liberia",
"Libya",
"Madagascar",
"Malawi",
"Mali",
"Mauritania",
"Mauritius",
"Mayotte",
"Morocco",
"Mozambique",
"Namibia",
"Niger",
"Nigeria",
"Republic of the Congo",
"Rwanda",
"Saint Helena",
"Sao Tome and Principe",
"Sao Tome",
"Senegal",
"Seychelles",
"Sierra Leone",
"Somalia",
"South Africa",
"Sudan",
"Swaziland",
"Tanzania",
"Togo",
"Tunisia",
"Uganda",
"Western Sahara",
"Zanzibar",
"Zambia",
"Zimbabwe"]
ANTARCTICA=[
"Antarctica"]
ASIA=[
"Afghanistan",
"Bahrain",
"Bangladesh",
"Bhutan",
"Brunei",
"Burma",
"Myanmar",
"Cambodia",
"Christmas Island",
"China",
"East Timor",
"Hong Kong",
"India",
"Indonesia",
"Iran",
"Iraq",
"Isle Of Man",
"Israel",
"Japan",
"Jordan",
"Kazakhstan",
"Korea (north)",
"Korea (south)",
"Korea",
"Kuwait",
"Kyrgyzstan",
"Laos",
"Lebanon",
"Malaysia",
"Maldives",
"Macao",
"Macau",
"Mongolia",
"Nepal",
"North Korea",
"Oman",
"Palestine",
"Pakistan",
"Philippines",
"Qatar",
"Russia",
"Saudi Arabia",
"Singapore",
"South Korea",
"Sri Lanka",
"Syria",
"Taiwan",
"Tajikistan",
"Thailand",
"Turkey",
"Turkmenistan",
"United Arab Emirates",
"Uzbekistan",
"Vietnam",
"Yemen"]
EUROPE=[
"Albania",
"Andorra",
"Armenia",
"Austria",
"Azerbaijan",
"Belarus",
"Belgium",
"Bosnia and Herzegovina",
"Bulgaria",
"Croatia",
"Cyprus",
"Czech Republic",
"Denmark",
"Estonia",
"Finland",
"France",
"Faroe Islands",
"Georgia",
"Germany",
"Gibraltar",
"Guernsey",
"Greece",
"Hungary",
"Iceland",
"Ireland",
"Italy",
"Jersey",
"Latvia",
"Liechtenstein",
"Lithuania",
"Luxembourg",
"Macedonia",
"Malta",
"Moldova",
"Monaco",
"Montenegro",
"Netherlands",
"Norway",
"Poland",
"Portugal",
"Romania",
"Russia",
"San Marino",
"Serbia",
"Slovakia",
"Slovenia",
"Spain",
"Sweden",
"Switzerland",
"Ukraine",
"United Kingdom",
"Vatican City"]
NORTH_AMERICA=[
"Anguilla",
"Antigua",
"Antigua And Barbuda",
"Aruba",
"Bahamas",
"Barbados",
"Belize",
"Bermuda",
"British Virgin Islands",
"Canada",
"Cayman Islands",
"Costa Rica",
"Cuba",
"Dominica",
"Dominican Republic",
"El Salvador",
"Florida",
"Greenland",
"Grenada",
"Guadeloupe",
"Guatemala",
"Haiti",
"Hawaii",
"Honduras",
"Jamaica",
"Martinique",
"Mexico",
"Montserrat",
"Nicaragua",
"Panama",
"Puerto Rico",
"St. Kitts & Nevis",
"Saint Kitts and Nevis",
"St. Lucia",
"Saint Lucia",
"Saint Pierre and Miquelon",
"St. Vincent & the Grenadines",
"Saint Vincent and the Grenadines",
"Trinidad & Tobago",
"Trinidad and Tobago",
"Turks and Caicos Islands",
"The Bahamas",
"United States",
"US Virgin Islands"]
OCEANIA=[
"Australia",
"Cook Islands",
"Federated States of Micronesia",
"Fiji",
"French Polynesia",
"Guam",
"Kiribati",
"Marshall Islands",
"Micronesia",
"New Caledonia",
"Nauru",
"New Zealand",
"Northern Mariana Islands",
"Palau",
"Papua New Guinea",
"Pitcairn Islands",
"Samoa",
"Solomon Islands",
"Tonga",
"Tuvalu",
"Vanuatu"]
SOUTH_AMERICA=[
"Argentina",
"Bolivia",
"Brazil",
"Chile",
"Colombia",
"Ecuador",
"Guyana",
"French Guiana",
"Netherlands Antilles",
"Paraguay",
"Peru",
"Suriname",
"Uruguay",
"Venezuela"]
COUNTRIES=[
"Afghanistan",
"Albania",
"Algeria",
"Andorra",
"Angola",
"Anguilla",
"Antarctica",
"Antigua",
"Antigua And Barbuda",
"Argentina",
"Armenia",
"Aruba",
"Australia",
"Austria",
"Azerbaijan",
"Bahamas",
"Bahrain",
"Bangladesh",
"Barbados",
"Belarus",
"Belgium",
"Belize",
"Benin",
"Bermuda",
"Bhutan",
"Bolivia",
"Bosnia and Herzegovina",
"Botswana",
"Brazil",
"British Virgin Islands",
"Brunei",
"Bulgaria",
"Burkina Faso",
"Burma",
"Burundi",
"Cambodia",
"Cameroon",
"Canada",
"Cape Verde",
"Cayman Islands",
"Côte d'Ivoire",
"Central African Republic",
"Chad",
"Chile",
"China",
"Christmas Island",
"Colombia",
"Comoros",
"Congo",
"Cook Islands",
"Costa Rica",
"Cote d'Ivoire",
"Croatia",
"Cuba",
"Cyprus",
"Czech Republic",
"Democratic Republic Congo",
"Denmark",
"Djibouti",
"Dominica",
"Dominican Republic",
"Ecuador",
"Egypt",
"El Salvador",
"Eritrea",
"Estonia",
"Ethiopia",
"Faroe Islands",
"Federated States of Micronesia",
"Fiji",
"Finland",
"Florida",
"France",
"French Guiana",
"French Polynesia",
"Gabon",
"Gambia",
"Georgia",
"Germany",
"Ghana",
"Gibraltar",
"Greece",
"Greenland",
"Grenada",
"Guadeloupe",
"Guam",
"Guatemala",
"Guernsey",
"Guinea",
"Guinea-Bissau",
"Guyana",
"Haiti",
"Hawaii",
"Honduras",
"Hong Kong",
"Hungary",
"Iceland",
"India",
"Indonesia",
"Iran",
"Iraq",
"Ireland",
"Isle Of Man",
"Israel",
"Italy",
"Jamaica",
"Japan",
"Jersey",
"Jordan",
"Kazakhstan",
"Kenya",
"Kiribati",
"Korea",
"Kuwait",
"Kyrgyzstan",
"Laos",
"Latvia",
"Lebanon",
"Liberia",
"Libya",
"Liechtenstein",
"Lithuania",
"Luxembourg",
"Macao",
"Macau",
"Macedonia",
"Madagascar",
"Malawi",
"Malaysia",
"Maldives",
"Mali",
"Malta",
"Martinique",
"Mauritania",
"Mauritius",
"Mayotte",
"Mexico",
"Moldova",
"Monaco",
"Mongolia",
"Montenegro",
"Montserrat",
"Morocco",
"Mozambique",
"Myanmar",
"Namibia",
"Nepal",
"Netherlands",
"Netherlands Antilles",
"New Caledonia",
"New York",
"New Zealand",
"Nicaragua",
"Niger",
"Nigeria",
"North Korea",
"Northern Mariana Islands",
"Norway",
"Oman",
"Pakistan",
"Palau",
"Palestine",
"Panama",
"Papua New Guinea",
"Paraguay",
"Pennsylvania",
"Peru",
"Philippines",
"Pitcairn",
"Poland",
"Portugal",
"Puerto Rico",
"Qatar",
"Réunion",
"Republic of the Congo",
"Reunion",
"Romania",
"Russia",
"Rwanda",
"Saint Helena",
"Saint Kitts and Nevis",
"Saint Lucia",
"Saint Pierre and Miquelon",
"Saint Vincent and the Grenadines",
"Samoa",
"San Marino",
"Sao Tome",
"Saudi Arabia",
"Senegal",
"Serbia",
"Seychelles",
"Sierra Leone",
"Singapore",
"Slovakia",
"Slovenia",
"Solomon Islands",
"Somalia",
"South Africa",
"South Korea",
"South Lanarkshire",
"Spain",
"Sri Lanka",
"St. Lucia",
"Sudan",
"Suriname",
"Swaziland",
"Sweden",
"Switzerland",
"Syria",
"Taiwan",
"Tanzania",
"Thailand",
"The Bahamas",
"The Gambia",
"Togo",
"Trinidad and Tobago",
"Tunisia",
"Turkey",
"Turkmenistan",
"Turks and Caicos Islands",
"Uganda",
"Ukraine",
"United Arab Emirates",
"United Kingdom",
"United States",
"Uruguay",
"US Virgin Islands",
"Uzbekistan",
"Vanuatu",
"Venezuela",
"Vietnam",
"Western Sahara",
"Yemen",
"Zambia",
"Zanzibar",
"Zimbabwe"]
CONTINENTS={}
CONTINENTS.merge!(AFRICA.map{|contry| [contry,"Africa"]}.inject({}) { |state, (key, val)| state.merge(key => val) })
CONTINENTS.merge!(ASIA.map{|contry| [contry,"Asia"]}.inject({}) { |state, (key, val)| state.merge(key => val) })
CONTINENTS.merge!(EUROPE.map{|contry| [contry,"Europe"]}.inject({}) { |state, (key, val)| state.merge(key => val) })
CONTINENTS.merge!(NORTH_AMERICA.map{|contry| [contry,"North America"]}.inject({}) { |state, (key, val)| state.merge(key => val) })
CONTINENTS.merge!(OCEANIA.map{|contry| [contry,"Oceania"]}.inject({}) { |state, (key, val)| state.merge(key => val) })
CONTINENTS.merge!(SOUTH_AMERICA.map{|contry| [contry,"South America"]}.inject({}) { |state, (key, val)| state.merge(key => val) })
CONTINENTS.merge!(ANTARCTICA.map{|contry| [contry,"Antarctica"]}.inject({}) { |state, (key, val)| state.merge(key => val) })
puts "Recognized"
COUNTRIES.each{|country| puts country +" => "+ CONTINENTS[country] if !CONTINENTS[country].nil?}
puts "Not recognized"
COUNTRIES.each{|country| puts country if CONTINENTS[country].nil?}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment