0.01
No commit activity in last 3 years
No release in over 3 years
Get countries by continent, or find the continents for a country given ISO 3166-1 alpha-2, alpha-3 and numeric codes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

ruby-continent

Build Status

ruby-continent provides a mechanism to get the continent for a given country, or to get the countries given a continent. Effort has been made to make the library very light weight and efficient.

Countries are returned as a hash in the following format:

{
  :name => 'Turkey, Republic of',
  :continent_codes => ['EU', 'AS'],
  :alpha_2_code => 'TR',
  :alpha_3_code => 'TUR',
  :numeric_code => 792
}

The Turkey example demonstrates how continent codes are given as an array, as some countries can belong to multiple continents. Countries which only belong to one continent are also given as an array.

Functions

By country

There are a few methods to select a country, based on ISO 3166-1 codes. These all return a single country in the format above, or nil if not found.

Continent.by_alpha_2_code('AU')
Continent.by_alpha_3_code('AUS')
Continent.by_numeric_code(36)

By continent

The following function takes a continent code and returns an array of countries in the format above, or nil if the continent is invalid.

Continent.by_continent_code('OC')

Continent codes and names are defined in share/continent_names.yml.

Getting continent name from a code

There is a helper method to get the continent name from the code, as codes are used inside the country hashes.

Continent.continent_name('OC')

Getting access to the underlying data

Full access to the underlying data is available via Continent.data, which is lazily loaded.

License

Please see COPYING provided with these source files.