Country Codes Rails Plugin
The Country Codes plugin finds and converts between country information as described in ISO 3166-1 (wikipedia): ISO 3166-1, as part of the ISO 3166 standard, provides codes for the names of countries and dependent territories, and is published by the International Organization for Standardization (ISO). The official name of the standard is Codes for the representation of names of countries and their subdivisions.
The Country Codes Rails Plugin supports the following ISO 3166-1 attributes: Country Name (name), Alpha-2 code (a2), Alpha-3 code (a3) and Numeric code (numeric).
Installation
From your rails applications root path:
./script/plugin install http://opensvn.csie.org/country_codes/trunk/ Operation
There are two current ways of invoking the plugin:
find_by_ATTRIBUTE
returns a hash of the search result
CountryCodes.find_by_name('Australia')
{:a3=>"AUS", :numeric=>36, :name=>"Australia", :a2=>"AU"}
find_ATTRIBUTE_by_ATTRIBUTE
returns a value of the resutling result
CountryCodes.find_name_by_a3('SWZ')
"Swaziland"
countries_for_select
returns an array of values that can be used in a select tag
CountryCodes.countries_for_select('name', 'a2')
[["Nepal", "NP"], ["Rwanda", "RW"], ... more ... ]
CountryCodes.countries_for_select('name', 'a2', 'name', 'a3')
[["Nepal", "NP", "Nepal", "NPL"], ... more ... ]