Search code examples
ruby-on-railsrubylistcountries

How to check if a country belongs to Europe


I'd like to check if the country name provided belongs to Europe. Does anyone know of a list of european countries that can be used in a Ruby project?

I'd like to do something like this:

spain = Country.named('Spain')

spain.parent # => 'Europe'

japan = Country.named('Japan')

japan.parent # => 'Asia'

https://github.com/jim/carmen/ lets me list subregions of a country, but not a country's parent.


Solution

  • Try that gem if you really need whole gem for this. You should be able to do:

    Country.find_all_countries_by_region('Europe')
    

    to get countries in Europe.