Git Product home page Git Product logo

countries's Introduction

Countries

Countries is a collection of all sorts of useful information for every country in the ISO 3166 standard. It contains info for the following standards ISO3166-1 (countries), ISO3166-2 (states/subdivisions), ISO4217 (currency) and E.164 (phone numbers).

The data used in this gem is also available as git submodules in YAML and JSON files.

Gem Version Tests Code Climate CodeQL

Installation

 gem install countries

Or you can install via Bundler if you are using Rails:

bundle add countries

Basic Usage

Simply load a new country object using Country.new(alpha2) or the shortcut Country[alpha2]. An example works best.

c = ISO3166::Country.new('US')

Get all country codes (alpha2).

ISO3166::Country.codes
#  ["TJ", "JM", "HT",...]

Configuration

Country Helper

Some apps might not want to constantly call ISO3166::Country this gem has a helper that can provide a Country class

# With global Country Helper
c = Country['US']

This will conflict with any existing Country constant

To Use

gem 'countries', require: 'countries/global'

Upgrading to 4.2 and 5.x

Release 4.2.0 introduced changes to name attributes and finders and deprecated several methods to resolve some existing confusion regardign official ISO country names vs. the "common names" that are commonly used.

The 5.0 release removed these deprecated methods and also removed support for Ruby 2.5 and 2.6

Plase see UPGRADE.md for more information

Attribute-Based Finder Methods

You can lookup a country or an array of countries using any of the data attributes via the find_country_by_attribute dynamic methods:

c    = ISO3166::Country.find_country_by_iso_short_name('italy')
c    = ISO3166::Country.find_country_by_any_name('united states')
h    = ISO3166::Country.find_all_by(:translated_names, 'França')
list = ISO3166::Country.find_all_countries_by_region('Americas')
c    = ISO3166::Country.find_country_by_alpha2("FR")

For a list of available attributes please see ISO3166::DEFAULT_COUNTRY_HASH. Note: searches are case insensitive and ignore accents.

Please note that find_by_name, find_by_names, find_*_by_name and find_*_by_names methods were removed in 5.0. See UPGRADE.md for more information

Country Info

Identification Codes

c.number # => "840"
c.alpha2 # => "US"
c.alpha3 # => "USA"
c.gec    # => "US"

Names & Translations

c.iso_long_name # => "The United States of America"
c.iso_short_name # => "United States of America"
c.common_name # => "United States" (This is a shortcut for c.translations('en'))
c.unofficial_names # => ["United States of America", "Vereinigte Staaten von Amerika", "États-Unis", "Estados Unidos"]

# Get the names for a country translated to its local languages
c = Country[:BE]
c.local_names # => ["België", "Belgique", "Belgien"]
c.local_name # => "België"

# Get a specific translation
c.translation('de') # => 'Vereinigte Staaten von Amerika'
c.translations['fr'] # => "États-Unis"

# Get all translations for a locale, defaults to 'en'
ISO3166::Country.translations         # {"DE"=>"Germany",...}
ISO3166::Country.translations('de')   # {"DE"=>"Deutschland",...}
ISO3166::Country.all_translated       # ['Germany', ...]
ISO3166::Country.all_translated('de') # ['Deutschland', ...]

# Nationality
c.nationality # => "American"

Subdivisions & States

c.subdivisions # => {"CO" => {"name" => "Colorado", "names" => "Colorado"}, ... }
c.subdivision_types # => ["state", "outlying_area", "district"]
c.subdivisions_of_types(['state']) # => {"CO" => {"name" => "Colorado", "names" => "Colorado"}, ... }
c.humanized_subdivision_types # => ["State", "Outlying area", "District"]

# This is now deprecated. #states is an alias of #subdivisions and returns all subdivisions regardless of type
c.states # => {"CO" => {"name" => "Colorado", "names" => "Colorado"}, ... }


# Get specific translations for the country subdivisions
c.subdivision_names_with_codes('es') #=> [ ..., ["Nuevo Hampshire", "NH"], ["Nueva Jersey", "NJ"], ... ]

# Subdivision code with translations for all loaded locales
c.subdivisions['NY'].code_with_translations #=> {"NY"=>{"en"=>"New York"}, ...}

#find_subdivision_by_name Find a country's state using its code or name in any translation

> ISO3166::Country.new("IT").find_subdivision_by_name("Toscana").geo
 => {"latitude"=>43.771389, "longitude"=>11.254167, ... }
> ISO3166::Country.new("IT").find_subdivision_by_name("Tuscany").geo
 => {"latitude"=>43.771389, "longitude"=>11.254167, ... }

Location

c.latitude # => "37.09024"
c.longitude # => "-95.712891"

c.world_region # => "AMER"
c.region # => "Americas"
c.subregion # => "Northern America"

Please note that latitude_dec and longitude_dec were deprecated on release 4.2 and removed in 5.0. These attributes have been redundant for several years, since the latitude and longitude fields have been switched decimal coordinates.

Timezones (optional)

Add tzinfo to your Gemfile and ensure it's required, Countries will not do this for you.

gem 'tzinfo', '~> 1.2', '>= 1.2.2'
c.timezones.zone_identifiers # => ["America/New_York", "America/Detroit", "America/Kentucky/Louisville", ...]
c.timezones.zone_info  # see [tzinfo docs](https://www.rubydoc.info/gems/tzinfo/TZInfo/CountryTimezone)
c.timezones # see [tzinfo docs](https://www.rubydoc.info/gems/tzinfo/TZInfo/Country)

Telephone Routing (E164)

c.country_code # => "1"
c.national_destination_code_lengths # => 3
c.national_number_lengths # => 10
c.international_prefix # => "011"
c.national_prefix # => "1"

Boundary Boxes

c.min_longitude # => '45'
c.min_latitude # => '22.166667'
c.max_longitude # => '58'
c.max_latitude # => '26.133333'

c.bounds #> {"northeast"=>{"lat"=>22.166667, "lng"=>58}, "southwest"=>{"lat"=>26.133333, "lng"=>45}}

European Union Membership

c.in_eu? # => false

European Economic Area Membership

c.in_eea? # => false

European Single Market Membership

c.in_esm? # => false

EU VAT Area membership

c.in_eu_vat? # => false

GDPR Compliant (European Economic Area Membership or UK)

c.gdpr_compliant? # => false

Country Code in Emoji

c = Country['MY']
c.emoji_flag # => "🇲🇾"

Country Distance Unit (miles/kilometres)

c.distance_unit # => "MI"

Plucking multiple attributes

ISO3166::Country.pluck(:alpha2, :iso_short_name) # => [["AD", "Andorra"], ["AE", "United Arab Emirates"], ...

.collect_countries_with allows to collect various countries' informations using any valid method and query value:

> ISO3166::Country.collect_countries_with("VR",:subdivisions,:common_name)
 => ["Italy", "Monaco"]
> ISO3166::Country.collect_countries_with("Caribbean",:subregion,:languages_spoken).flatten.uniq
 => ["en", "fr", "es", "ht", "nl"]
> ISO3166::Country.collect_countries_with("Oceania",:region,:international_prefix).uniq
 => ["00", "011", "0011", "19", "05"]
> ISO3166::Country.collect_countries_with("Antarctica",:continent,:emoji_flag)
 => ["🇦🇶", "🇬🇸", "🇧🇻", "🇹🇫", "🇭🇲"]
> ISO3166::Country.collect_countries_with("🇸🇨",:emoji_flag,:common_name)
 => ["Seychelles"]

.collect_likely_countries_by_subdivision_name allows to lookup all countries having the given state code or state name (in any translation)

ISO3166::Country.collect_likely_countries_by_subdivision_name("San José",:common_name)
 => ["Costa Rica", "Uruguay"]

Conversions

ISO3166::Country.from_alpha3_to_alpha2('USA') # => "US"
ISO3166::Country.from_alpha2_to_alpha3('US') # => "USA"

ISO3166::Country.from_alpha2_to_alpha3('--') # => nil

Currencies

To enable currencies extension please add the following to countries initializer.

ISO3166.configuration.enable_currency_extension!

Please note that it requires you to add "money" dependency to your gemfile.

gem "money", "~> 6.9"

Countries now uses the Money gem. What this means is you now get back a Money::Currency object that gives you access to all the currency information.

c = ISO3166::Country['us']
c.currency.iso_code # => 'USD'
c.currency.name # => 'United States Dollar'
c.currency.symbol # => '$'

Address Formatting

A template for formatting addresses is available through the address_format method. These templates are compatible with the Liquid template system.

c.address_format # => "{{recipient}}\n{{street}}\n{{city}} {{region}} {{postalcode}}\n{{country}}"

Selective Loading of Locales

As of 2.0 you can selectively load locales to reduce memory usage in production.

By default we load I18n.available_locales if I18n is present, otherwise only [:en]. This means almost any Rails environment will only bring in its supported translations.

You can add all the locales like this.

ISO3166.configure do |config|
  config.locales = [:af, :am, :ar, :as, :az, :be, :bg, :bn, :br, :bs, :ca, :cs, :cy, :da, :de, :dz, :el, :en, :eo, :es, :et, :eu, :fa, :fi, :fo, :fr, :ga, :gl, :gu, :he, :hi, :hr, :hu, :hy, :ia, :id, :is, :it, :ja, :ka, :kk, :km, :kn, :ko, :ku, :lt, :lv, :mi, :mk, :ml, :mn, :mr, :ms, :mt, :nb, :ne, :nl, :nn, :oc, :or, :pa, :pl, :ps, :pt, :"pt-BR", :ro, :ru, :rw, :si, :sk, :sl, :so, :sq, :sr, :sv, :sw, :ta, :te, :th, :ti, :tk, :tl, :tr, :tt, :ug, :uk, :ve, :vi, :wa, :wo, :xh, :"zh-cn", :"zh-tw", :zu]
end

or something a bit more simple

ISO3166.configure do |config|
  config.locales = [:en, :de, :fr, :es]
end

If you change the value of ISO3166.configuration.locales after initialization, you should call ISO3166::Data.reset to reset the data cache, or you may end up with inconsistently loaded locales. As of 5.1.1, subdivision translations also respect this and will only load the selected locales.

Loading Custom Data

As of 2.0 countries supports loading custom countries / overriding data in its data set, though if you choose to do this please contribute back to the upstream repo!

Any country registered this way will have its data available for searching etc... If you are overriding an existing country, for cultural reasons, our code uses a simple merge, not a deep merge so you will need to bring in all data you wish to be available. Bringing in an existing country will also remove it from the internal management of translations, all registered countries will remain in memory.

ISO3166::Data.register(
  alpha2: 'LOL',
  iso_short_name: 'Happy Country',
  translations: {
    'en' => 'Happy Country',
    'de' => 'glückliches Land'
  }
)

ISO3166::Country.new('LOL').iso_short_name == 'Happy Country'

Mongoid

Mongoid support has been added. It is required automatically if Mongoid is defined in your project.

Use native country fields in your model:

field :country, type: Country

Adds native support for searching/saving by a country object or alpha2 code.

Searching:

# By alpha2
spanish_things = Things.where(country: 'ES')
spanish_things.first.country.iso_short_name    # => "Spain"

# By object
spanish_things = Things.where(country: Country.find_by_iso_short_name('Spain')[1])
spanish_things.first.country.iso_short_name    # => "Spain"

Saving:

# By alpha2
spanish_things = Thing.new(country: 'ES')
spanish_things.save!
spanish_things.country.iso_short_name    # => "Spain"

# By object
spanish_things = Thing.new(country: Country.find_by_iso_short_name('Spain')[1])
spanish_things.save!
spanish_things.country.iso_short_name    # => "Spain"

Note that the database stores only the alpha2 code and rebuilds the object when queried. To return the country name by default you can override the reader method in your model:

def country
  super.iso_short_name
end

Note on Patches/Pull Requests

Please do not submit pull requests on cache/**/*. These files generated by a rake task when preparing new releases and are not meant to be manually updated.

If you with to submit a PR to update or correct country data, please edit the corresponding YAML file lib/countries/data/**. Changes to the YAML files will be injected during the next rake update_cache.

This project seeks to follow ISO3166, ISO4217 and E.164 standards in its data.

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Copyright

Copyright (c) 2012-2015 hexorx
Copyright (c) 2015-2021 hexorx, rposborne
Copyright (c) 2022 hexorx, rposborne, pmor

See LICENSE for details.

countries's People

Contributors

cllns avatar dachusa avatar digipie avatar durhamka avatar dwilkie avatar esfourteen avatar franckverrot avatar gui avatar hexorx avatar jeremywrowe avatar jgrau avatar jrdi avatar kasparsj avatar lorddoig avatar lukkry avatar mbirman avatar mezza avatar msuliq avatar pezholio avatar philipefarias avatar pmor avatar pr0d1r2 avatar rogerpodacter avatar rposborne avatar rvdheijden avatar skarlcf avatar stayhero avatar stefkin avatar sykaeh avatar yuanping avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

countries's Issues

Remove class Country <...

Could you please remove this part from the gem so that it is usable with a rails project that has a model called Country?

class Country < ISO3166::Country
end

Translations for subdivision names

Is there a way to determine what each name listed in names, for subdivisions, belongs to which language?

It was simple to figure this out for the countries, since each entry has a translations table.

ActiveRecord support

Do you plan active record support?
So that it is possible to do a migration:

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :name
      t.belongs_to :country
    end
  end
end

EDIT:
I forgot: Nice gem and nice work! Congratulations... 👍

Include Needs Zip?

Hi!

Just wanted to see if there was any interest in building out a "Requires Zip?" method, as a bunch of random countries don't have a postal code to speak of.

Lengths of national numbers in Germany is incorrect

According to countries.yaml the lengths of national numbers varies between 7 and 11, but that is incorrect.

The "E.164 National Numbering Plan" for Germany lists the length of national significant numbers between 6 and 11 (with the exception of mobile numbers and special services where the length can vary between 3 and 14) (Source: http://www.itu.int/dms_pub/itu-t/oth/02/02/T02020000510001PDFE.pdf)

PS:
There are also some historic numbers which can be shorter than 6. For example the number of the city administration of Gelsenkirchen is 1690 (Source: http://www.gelsenkirchen.de/de/Funktionsnavigation/kontakt.asp)

But I'm not sure if they should be included...

Mongoid NoMethodError: undefined method `name' for "AT":String

Hi there,

I am using MONGOID with COUNTRIES.

As described in the readme

I added this in my User model:

field :country, type: Country

>> u.country = 'AT'
"AT"

>> u.save!
true

>> u.country
"AT"

>> u.country.name
NoMethodError: undefined method `name' for "AT":String

I don't wanna save the whole object

What I am doing wrong?

best regards

Jan

Should 'UK' be recognized?

I just found out that UK is not an official short name for United Kingdom and Countries gem doesn't find it when trying 'Country.new('UK')'. This really surprises me as 'UK' is so widely used. Should Countries gem have support for this kind of widely used but unofficial short names? Is there many more of these?

Maybe 'UK' could be added as an alternative name for United Kingdom.

Issue with Rails 3.1.4 & country_select

country_select returns an empty select with a lot of these warnings:

rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.4/lib/active_support/core_ext/string/output_safety.rb:23: warning: regexp match /.../n against to UTF-8 string

Thanks for your gem!

Example for ExchangeBank does not work

I installed latest countries, money, and currencies gems, and the exchangebank example does not work:

Money.default_bank = Currency::ExchangeBank.new
=> #<ISO4217::Currency::ExchangeBank:0x1106187b0 @mutex=#Mutex:0x110618378, @rates={}>
Money.us_dollar(100).exchange_to("CAD")
NoMethodError: undefined method exchange_with' for #<ISO4217::Currency::ExchangeBank:0x1106187b0> from /Library/Ruby/Gems/1.8/gems/money-4.0.2/lib/money/money.rb:320:inexchange_to'
from (irb):60

uninitialized constant InmycountryController::Country

Probably a beginner question, but I take the risk to ask.
I'm creating my first Ruby application (more of a javascript developer), and countries is the first gem library I'm using, so, i may not be aware of every step. What I did:
I added

gem 'countries'
gem 'country_select'

to the gemfile on the root of my project.
I ran bundle update, in my project directory (btw, i'm on mac OSX Mountain lion)
and if I do a gem list, it shows me the packages are installed:

gem list
[...]
countries (0.9.2)
country_select (1.1.3)
[...]

So everything seems to be good. But then, when in my controller I do

c = Country.new('US')

I get the following error _uninitialized constant InmycountryController::Country_
(inmycountry is the name of my app).

I then tried different vodoo fix from things i find from the internet, esp.

require("countries")

but it says: _cannot load such file -- countries_
Am I doing something wrong?

rails version: 3.2.13
ruby version 2.0.0p0

Custom Data

Is it possible for me to add some custom fields to each country in addition to the ones provided in the YAML file so I can access that data via the Country class?

Thanks!

Feature Proposal: Language spoken in country

For a project I need the language spoken in each country. I think it would be great if the countries gem would include this information?

Before I would work on a pull request I'd like to know if anyone else is interested and if you consider to include this feature?

What do you think?

Subdivision tiers

Hey

This page http://en.wikipedia.org/wiki/ISO_3166-2:GB specifies subdivision names as listed in the ISO 3166-2 standard

There are 4 codes ENG, NIR, SCT and WL (England, Northern Ireland, Scotland and Wales) that are higher tiered than what the gem currently returns as UK subdivisions.

This means that we have different tiers of subdivisions, where the gem currently only supports the lowest level

Will you be able to implement this, and if not, do you prefer an approach that we could take and submit a pull request?

Much appreciated

  • Mads

Translations not working in Rails 3

When I use
c.translations['fr']
in rails 3 i get the following error

NoMethodError: undefined method `translations' for #Country:0x007fc945942968

Time for a version bump?

Translations method is not available in 0.9.2, the last version released to rubygems. I was just hit for this after getting back from my fork (my PR just got accepted). Maybe it's a good time for a new version bump release to rubygems?

Cheers and thanks for good work!

Separate data files and data format validation?

Just a couple of queries:

  1. Is there a reason the database is packaged as a single file? It seems that maintenance would be easier if they were split into separate files.
  2. Is there a specification / validator for the schema? A rake task that ensures compliance would be handy.

Happy to take these on if you're interested.

Russian Federation displaying as Russia in country_select

I am using your Gem with the country_select gem to allow registering users to select their country. In certain circumstances "Russian Federation" is being shown as "Russia". Since I am also using your country names for form validation an error is being thrown as it expects "Russian Federation".

This could be due to the English translation of "Russian Federation" to "Russia" in countries.yml.

Replace Currency gem with Money

I suggest to either replace Currency gem with Money gem, or make Money gem as an configurable option. (I guess, it would be better, because these gems have different interfaces)

My point: it seems that this gem is more popular, than Currency gem (based on github stars and ruby-toolbox.com).
Therefore, it's more likely that people would have Money gem already used in the project.

I had it in my project too and I don't want to use another gem that implements currencies.
Hence I created initializer and monkey-patched this gem to use Money::Currency class, instead of ISO4217::Currency.

class ISO3166::Country
  def currency
    Money::Currency.find(@data['currency'])
  end
end

That way I'm getting the same interface for Currency objects everywhere in my code.

If you need this functionality, I can implement it.

Is in_eu method working?

Hello,

It looks like the in_eu? method is not working.

2.0.0p247 :004 > c = Country.find_country_by_name('Sweden')
2.0.0p247 :024 > c.in_eu?
NoMethodError: undefined method `in_eu?' for #Country:0x007feed24bbb80

Am I using it correctly?

Value Added Tax

Hi

Would you be open for a PR, which adds value added tax data for all the countries? I need a couple country-based informations and your awesome gem provides all, except that.

Regex doesn't work

Hi
i try to find county by name with regex, but it doesn't work

c = Country.find_all_countries_by_name(/^T[A-Za-z ]*/)

Invalid gemspec

Hey,

Thanks for accepting the pull request... however after the update (and the gemspec being regenerated), I'm getting the following error (tried it across a couple of machines).

bundle install
bundle exec rake spec

WARNING:  #<ArgumentError: Illformed requirement ["#<YAML::Syck::DefaultKey:0xb54797fc> 0.4.0"]>
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
  s.name = %q{countries}
  s.version = "0.6.3"

  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
  s.authors = ["hexorx", "Joe Corcoran"]
  s.date = %q{2011-11-22 00:00:00.000000000Z}
  s.description = %q{All sorts of useful information about every country packaged as pretty little country objects. It includes data from ISO 3166 (countries and subdivisions), ISO 4217 (currency), and E.164 (phone numbers). As a bonus it even adds a country_select helper to rails projects.}
  s.email = %q{[email protected]}
  s.extra_rdoc_files = ["LICENSE", "README.markdown"]
  s.files = [".document", ".rvmrc", "Gemfile", "Gemfile.lock", "LICENSE", "README.markdown", "Rakefile", "VERSION", "countries.gemspec", "lib/countries.rb", "lib/countries/country.rb", "lib/countries/select_helper.rb", "lib/data/countries.yaml", "lib/data/subdivisions/AD.yaml", "lib/data/subdivisions/AE.yaml", "lib/data/subdivisions/AF.yaml", "lib/data/subdivisions/AG.yaml", "lib/data/subdivisions/AL.yaml", "lib/data/subdivisions/AM.yaml", "lib/data/subdivisions/AO.yaml", "lib/data/subdivisions/AR.yaml", "lib/data/subdivisions/AT.yaml", "lib/data/subdivisions/AU.yaml", "lib/data/subdivisions/AZ.yaml", "lib/data/subdivisions/BA.yaml", "lib/data/subdivisions/BB.yaml", "lib/data/subdivisions/BD.yaml", "lib/data/subdivisions/BE.yaml", "lib/data/subdivisions/BF.yaml", "lib/data/subdivisions/BG.yaml", "lib/data/subdivisions/BH.yaml", "lib/data/subdivisions/BI.yaml", "lib/data/subdivisions/BJ.yaml", "lib/data/subdivisions/BN.yaml", "lib/data/subdivisions/BO.yaml", "lib/data/subdivisions/BR.yaml", "lib/data/subdivisions/BS.yaml", "lib/data/subdivisions/BT.yaml", "lib/data/subdivisions/BW.yaml", "lib/data/subdivisions/BY.yaml", "lib/data/subdivisions/BZ.yaml", "lib/data/subdivisions/CA.yaml", "lib/data/subdivisions/CD.yaml", "lib/data/subdivisions/CF.yaml", "lib/data/subdivisions/CG.yaml", "lib/data/subdivisions/CH.yaml", "lib/data/subdivisions/CI.yaml", "lib/data/subdivisions/CL.yaml", "lib/data/subdivisions/CM.yaml", "lib/data/subdivisions/CN.yaml", "lib/data/subdivisions/CO.yaml", "lib/data/subdivisions/CR.yaml", "lib/data/subdivisions/CU.yaml", "lib/data/subdivisions/CV.yaml", "lib/data/subdivisions/CY.yaml", "lib/data/subdivisions/CZ.yaml", "lib/data/subdivisions/DE.yaml", "lib/data/subdivisions/DJ.yaml", "lib/data/subdivisions/DK.yaml", "lib/data/subdivisions/DM.yaml", "lib/data/subdivisions/DO.yaml", "lib/data/subdivisions/DZ.yaml", "lib/data/subdivisions/EC.yaml", "lib/data/subdivisions/EE.yaml", "lib/data/subdivisions/EG.yaml", "lib/data/subdivisions/EH.yaml", "lib/data/subdivisions/ER.yaml", "lib/data/subdivisions/ES.yaml", "lib/data/subdivisions/ET.yaml", "lib/data/subdivisions/FI.yaml", "lib/data/subdivisions/FJ.yaml", "lib/data/subdivisions/FM.yaml", "lib/data/subdivisions/FR.yaml", "lib/data/subdivisions/GA.yaml", "lib/data/subdivisions/GB.yaml", "lib/data/subdivisions/GD.yaml", "lib/data/subdivisions/GE.yaml", "lib/data/subdivisions/GH.yaml", "lib/data/subdivisions/GM.yaml", "lib/data/subdivisions/GN.yaml", "lib/data/subdivisions/GQ.yaml", "lib/data/subdivisions/GR.yaml", "lib/data/subdivisions/GT.yaml", "lib/data/subdivisions/GW.yaml", "lib/data/subdivisions/GY.yaml", "lib/data/subdivisions/HN.yaml", "lib/data/subdivisions/HR.yaml", "lib/data/subdivisions/HT.yaml", "lib/data/subdivisions/HU.yaml", "lib/data/subdivisions/ID.yaml", "lib/data/subdivisions/IE.yaml", "lib/data/subdivisions/IL.yaml", "lib/data/subdivisions/IN.yaml", "lib/data/subdivisions/IQ.yaml", "lib/data/subdivisions/IR.yaml", "lib/data/subdivisions/IS.yaml", "lib/data/subdivisions/IT.yaml", "lib/data/subdivisions/JM.yaml", "lib/data/subdivisions/JO.yaml", "lib/data/subdivisions/JP.yaml", "lib/data/subdivisions/KE.yaml", "lib/data/subdivisions/KG.yaml", "lib/data/subdivisions/KH.yaml", "lib/data/subdivisions/KI.yaml", "lib/data/subdivisions/KM.yaml", "lib/data/subdivisions/KN.yaml", "lib/data/subdivisions/KP.yaml", "lib/data/subdivisions/KR.yaml", "lib/data/subdivisions/KW.yaml", "lib/data/subdivisions/KZ.yaml", "lib/data/subdivisions/Ky.yaml", "lib/data/subdivisions/LA.yaml", "lib/data/subdivisions/LB.yaml", "lib/data/subdivisions/LI.yaml", "lib/data/subdivisions/LK.yaml", "lib/data/subdivisions/LR.yaml", "lib/data/subdivisions/LS.yaml", "lib/data/subdivisions/LT.yaml", "lib/data/subdivisions/LU.yaml", "lib/data/subdivisions/LV.yaml", "lib/data/subdivisions/LY.yaml", "lib/data/subdivisions/MA.yaml", "lib/data/subdivisions/MD.yaml", "lib/data/subdivisions/ME.yaml", "lib/data/subdivisions/MG.yaml", "lib/data/subdivisions/MH.yaml", "lib/data/subdivisions/MK.yaml", "lib/data/subdivisions/ML.yaml", "lib/data/subdivisions/MM.yaml", "lib/data/subdivisions/MN.yaml", "lib/data/subdivisions/MR.yaml", "lib/data/subdivisions/MU.yaml", "lib/data/subdivisions/MV.yaml", "lib/data/subdivisions/MW.yaml", "lib/data/subdivisions/MX.yaml", "lib/data/subdivisions/MY.yaml", "lib/data/subdivisions/MZ.yaml", "lib/data/subdivisions/NA.yaml", "lib/data/subdivisions/NE.yaml", "lib/data/subdivisions/NG.yaml", "lib/data/subdivisions/NI.yaml", "lib/data/subdivisions/NL.yaml", "lib/data/subdivisions/NO.yaml", "lib/data/subdivisions/NP.yaml", "lib/data/subdivisions/NR.yaml", "lib/data/subdivisions/NZ.yaml", "lib/data/subdivisions/OM.yaml", "lib/data/subdivisions/PA.yaml", "lib/data/subdivisions/PE.yaml", "lib/data/subdivisions/PG.yaml", "lib/data/subdivisions/PH.yaml", "lib/data/subdivisions/PK.yaml", "lib/data/subdivisions/PL.yaml", "lib/data/subdivisions/PT.yaml", "lib/data/subdivisions/PW.yaml", "lib/data/subdivisions/PY.yaml", "lib/data/subdivisions/QA.yaml", "lib/data/subdivisions/RO.yaml", "lib/data/subdivisions/RS.yaml", "lib/data/subdivisions/RU.yaml", "lib/data/subdivisions/RW.yaml", "lib/data/subdivisions/SA.yaml", "lib/data/subdivisions/SB.yaml", "lib/data/subdivisions/SC.yaml", "lib/data/subdivisions/SD.yaml", "lib/data/subdivisions/SE.yaml", "lib/data/subdivisions/SG.yaml", "lib/data/subdivisions/SH.yaml", "lib/data/subdivisions/SI.yaml", "lib/data/subdivisions/SK.yaml", "lib/data/subdivisions/SL.yaml", "lib/data/subdivisions/SM.yaml", "lib/data/subdivisions/SN.yaml", "lib/data/subdivisions/SO.yaml", "lib/data/subdivisions/SR.yaml", "lib/data/subdivisions/ST.yaml", "lib/data/subdivisions/SV.yaml", "lib/data/subdivisions/SY.yaml", "lib/data/subdivisions/SZ.yaml", "lib/data/subdivisions/TD.yaml", "lib/data/subdivisions/TF.yaml", "lib/data/subdivisions/TG.yaml", "lib/data/subdivisions/TH.yaml", "lib/data/subdivisions/TL.yaml", "lib/data/subdivisions/TM.yaml", "lib/data/subdivisions/TN.yaml", "lib/data/subdivisions/TO.yaml", "lib/data/subdivisions/TR.yaml", "lib/data/subdivisions/TT.yaml", "lib/data/subdivisions/TV.yaml", "lib/data/subdivisions/TW.yaml", "lib/data/subdivisions/TZ.yaml", "lib/data/subdivisions/Tj.yaml", "lib/data/subdivisions/UA.yaml", "lib/data/subdivisions/UG.yaml", "lib/data/subdivisions/UM.yaml", "lib/data/subdivisions/US.yaml", "lib/data/subdivisions/UY.yaml", "lib/data/subdivisions/UZ.yaml", "lib/data/subdivisions/VC.yaml", "lib/data/subdivisions/VE.yaml", "lib/data/subdivisions/VN.yaml", "lib/data/subdivisions/VU.yaml", "lib/data/subdivisions/WS.yaml", "lib/data/subdivisions/YE.yaml", "lib/data/subdivisions/ZA.yaml", "lib/data/subdivisions/ZM.yaml", "lib/data/subdivisions/ZW.yaml", "lib/iso3166.rb", "spec/country_spec.rb", "spec/spec_helper.rb"]
  s.homepage = %q{http://github.com/hexorx/countries}
  s.require_paths = ["lib"]
  s.rubygems_version = %q{1.3.7}
  s.summary = %q{Gives you a country object full of all sorts of useful information.}

  if s.respond_to? :specification_version then
    current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
    s.specification_version = 3

    if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
      s.add_runtime_dependency(%q<currencies>, ["#<YAML::Syck::DefaultKey:0xb54797fc> 0.4.0"])
      s.add_development_dependency(%q<jeweler>, [">= 1.6.4"])
      s.add_development_dependency(%q<rspec>, ["#<YAML::Syck::DefaultKey:0xb5477b14> 1.3.1"])
      s.add_development_dependency(%q<rake>, [">= 0"])
      s.add_development_dependency(%q<yard>, ["#<YAML::Syck::DefaultKey:0xb54754e0> 0.6.4"])
      s.add_runtime_dependency(%q<currencies>, [">= 0.2.0"])
      s.add_development_dependency(%q<rspec>, [">= 0"])
      s.add_development_dependency(%q<yard>, [">= 0"])
    else
      s.add_dependency(%q<currencies>, ["#<YAML::Syck::DefaultKey:0xb54797fc> 0.4.0"])
      s.add_dependency(%q<jeweler>, [">= 1.6.4"])
      s.add_dependency(%q<rspec>, ["#<YAML::Syck::DefaultKey:0xb5477b14> 1.3.1"])
      s.add_dependency(%q<rake>, [">= 0"])
      s.add_dependency(%q<yard>, ["#<YAML::Syck::DefaultKey:0xb54754e0> 0.6.4"])
      s.add_dependency(%q<currencies>, [">= 0.2.0"])
      s.add_dependency(%q<rspec>, [">= 0"])
      s.add_dependency(%q<yard>, [">= 0"])
    end
  else
    s.add_dependency(%q<currencies>, ["#<YAML::Syck::DefaultKey:0xb54797fc> 0.4.0"])
    s.add_dependency(%q<jeweler>, [">= 1.6.4"])
    s.add_dependency(%q<rspec>, ["#<YAML::Syck::DefaultKey:0xb5477b14> 1.3.1"])
    s.add_dependency(%q<rake>, [">= 0"])
    s.add_dependency(%q<yard>, ["#<YAML::Syck::DefaultKey:0xb54754e0> 0.6.4"])
    s.add_dependency(%q<currencies>, [">= 0.2.0"])
    s.add_dependency(%q<rspec>, [">= 0"])
    s.add_dependency(%q<yard>, [">= 0"])
  end
end
WARNING:  Invalid .gemspec format in '/var/lib/gems/1.8/specifications/countries-0.6.3.gemspec'
Could not find countries-0.6.3 in any of the sources

Wondered if anyone else has seen it? The installed gemfile doesn't look right (the YAML::Syck::DefaultKey stuff in particular)

Feature proposal: Continent

It could be useful to retrieve information about continent from each country.

Before I would work on a pull request I'd like to know what do you think about this feature?

Subdivisions inconsistently include the country code

The subdivisions for the majority of countries are correctly specified as up to three characters that when combined with the country code give the full unique identifier for a region such as US-CA or FR-92. However, for at least Sweden the data wrongly contains the country code as part of the subdivision code making them longer than the three allowed characters.

NoMethodError

I'm using countries with country_select. Any method call results in the following error:

NoMethodError: undefined method `data' for #Object:0x00000001e04600

with trace leading to /gems/countries-0.9.3/lib/countries/country.rb:51:in `=='

Could you please take a look?

Override translations

Is there a way (except forking the gem), how to add missing translations or override existing?

country_select breaks in Rails 3.2.2

The country_options_for_select form helper does not return a safe string under rails 3.2.2. Rubygems is down at the moment so I can't fix right away, so thought I'd report it here for now. The fix is to mark the empty string on line 11 of lib/countries/select_helper.rb as html_safe.

Not so awesome print with awesome_print

There is an funny error for users testing this gem in theirs shells:

2.1.3 (main):0 > require 'countries'; Country['US']
(pry) output error: #<NoMethodError: undefined method `data' for #<Object:0x007f85fb0e1518>>

I tracked down the error to my Ruby shell (pry) loading the awesome_print gem, and have tested that this also fails for irb

The way to reproduce the error is just loading the shell without awesome print. The Country class prints OK. Now if you do...

require "awesome_print"
AwesomePrint.pry!
# ... or ... AwesomePrint.irb!

The error appears

Non existing countries

While working on the languages support I found that the Netherlands Antilles (AN) do not exist anymore (since 2010, see http://en.wikipedia.org/wiki/Netherlands_Antilles).

Is it planned to keep non existing countries in the "database" e.g. for backwards compatibility? Probably it would be worth to add a flag to each country (e.g. if it still exists)?

Accent-insensitive matching

It would be quite useful to ignore characters with accents when comparing country names, since often people type in country names without those.

Include subdivision terminology

I would like to add first-level subdivision terminology to the country data. In other words, given a country we know which of the following terms it uses:

  • State
  • Region
  • Territory
  • Province
  • Prefecture
  • Governorate
  • Department
  • County
  • Canton
  • Parish
  • District
  • Municipality

I would base this information off of Wikipedia's Matrix of Country Subdivisions and the ISO 3166-2 primary codes which I could probably pull from oodavid's iso_3166_2.js. Would a pull request be welcome?

Feature request - Have aliases for countries

It would be great if you could have aliases for countries (not just translations). For example "United States of America" Is also known as:

  • USA
  • U.S.A
  • America

This would make matching country names from databases a lot easier.

country_select breaks with Rails 4

Hi,
when using your country_select-helper in rails 4, it breaks. It seems that there are some changes in the view layer. However, I have found a workaround, which is probably better than including the select helper in this gem. Add the following to the Gemfile:

gem 'countries'
gem 'country_select', require: false

and create an initializer with the the following code:

ActionView::Helpers::FormOptionsHelper::COUNTRIES = ISO3166::Country::Names.map{ |(name,alpha2)| [name.html_safe,alpha2] }
require 'country_select'

I suggest that you add these instructions to the README and remove the view helper from this gem. The advantage is that this gem doesn't have to provide the select helper itself (which is out if its scope in my opinion), but you can still offer your users the select helper by utilizing the country_select-gem, which is actively maintained.

What do you think? Best regards,
Fabian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.