This is a RubyGem wrapper library around the API provided by Restcountries.
Add this line to your application's Gemfile:
gem 'restcountry'
And then execute:
$ bundle
Or install it yourself as:
$ gem install restcountry
require 'restcountry'
# Find all countries
countries = Restcountry::Country.all
# Find a country by name
country = Restcountry::Country.find_by_name('italy')
# Access the country's attributes
country.capital
#=> Rome
country.region
#=> Europe
country.callingCodes
#=> "39"
# Find a country by capital
country = Restcountry::Country.find_by_capital('Rome')
country.name
#=> Italy
countries = Restcountry::Country.find_by_lang('it')
countries.first
#=> Holy See
name, capital, altSpellings, relevance, region, subregion, translations, population, latlng, demonym, area, gini, timezones, borders, nativeName, callingCodes, topLevelDomain, alpha2Code, alpha3Code, currencies, languages
Many thanks to Fayder Florez for his implementation of the API.
The restcountry GEM is released under the MIT License.