« Ruby Football Week 2021, June 11th to June 17th - 7 Days of Ruby (Sports) Gems

Day 1 - fifa Gem - The World’s Football Countries and Codes (Incl. Non-Member Countries and Irregular Codes)

Written by geraldb Gerald Bauer

Let’s start with a triva quiz. The United Nations has 193 member countries:

Q: How many member countries has the world football federation (FIFA)?

What’s the fifa Gem?

The fifa gem ships with all the world’s countries (incl. non-members or historic) and the countries’ official (or irregular) three-letter codes. Example:

Get and pretty print (pp) all countries

require 'fifa'

pp Fifa.countries

resulting in:

[#<Country @code="AFG", @key="af", @name="Afghanistan">,
 #<Country @code="ALB", @key="al", @name="Albania">,
 #<Country @code="ALG", @key="dz", @name="Algeria">,
 #<Country @code="ASA", @key="as", @name="American Samoa">,
 #<Country @code="AND", @key="ad", @name="Andorra">,
 #<Country @code="ANG", @key="ao", @name="Angola">,
 #<Country @code="AIA", @key="ai", @name="Anguilla">,
 #<Country @code="ATG", @key="ag", @name="Antigua and Barbuda">,
 #<Country @code="ARG", @key="ar", @name="Argentina">,
 #<Country @code="ARM", @key="am", @name="Armenia">,
 #<Country @code="ARU", @key="aw", @name="Aruba">,
 #<Country @code="AUS", @key="au", @name="Australia">,
 #<Country @code="AUT", @key="at", @name="Austria">,
 #<Country @code="AZE", @key="az", @name="Azerbaijan">,
 ...
]

Note: If you prefer you can use the all-upcase FIFA name as an alias for Fifa.

Let’s lookup some countries by the fifa (three-letter) code:

eng = Fifa['ENG']
# -or-
eng = Fifa['eng']
eng = Fifa[:eng]

eng.key    #=> "eng"
eng.name   #=> "England"
eng.code   #=> "ENG"


aut  = Fifa['AUT']
# -or-
aut  = Fifa['aut']
aut  = Fifa[:aut]

aut.key    #=> "at"
aut.name   #=> "Austria"
aut.code   #=> "AUT"

...

Or get all countries / members by continental confederation:

(a) Australia has been a member of the AFC since 2006.

(b) French Guiana, Guyana and Suriname are CONCACAF members although they are in South America. The French Guiana team is a member of CONCACAF but not of FIFA.

(c) Teams representing the nations of Armenia, Azerbaijan, Cyprus, Georgia, Israel, Kazakhstan, Russia and Turkey are UEFA members, although the majority or entirety of their territory is outside of continental Europe. Monaco is not member of UEFA or FIFA.

Fifa.members( 'FIFA' ).size          #=> 211 members  -or-
Fifa.members( 'World' ).size         #=> 211 members

Fifa.members( 'AFC' ).size           #=> 47 members   -or-
Fifa.members( 'Asia' ).size          #=> 47 members

Fifa.members( 'CAF').size            #=> 56 members  -or-
Fifa.members( 'Africa' ).size        #=> 56 members

Fifa.members( 'CONCACAF').size       #=> 41 members  -or-
Fifa.members( 'North, Central America and Caribbean').size   #=> 41 members

Fifa.members( 'CONMEBOL' ).size      #=> 10 members  -or-
Fifa.members( 'South America' ).size #=> 10 members

Fifa.members( 'OFC' ).size           #=> 14 members  -or-
Fifa.members( 'Oceania' ).size       #=> 14 members

Fifa.members( 'UEFA' ).size          #=> 55 members  -or-
Fifa.members( 'Europe' ).size        #=> 55 members

...

That’s it.

What’s FIFA¹?

The World’s Football Association / Governing Body uses its own country list and (three-letter²) codes - see the List of FIFA country codes @ Wikipedia or the countries.txt list shipping with this library.

Trivia - The FIFA member list includes 211 countries (in 2021) while the United Nations (UN) member list only includes 193 countries. For example, for historic reasons the FIFA includes:

but doesn’t include the United Kingdom (UK) itself. Or the FIFA includes (non-sovereign) dependent territories or autonomous regions that have their own national team or leagues, for example:

Note: This library includes non-FIFA member codes and irregular codes from countries in use by regional confederations too, for example:

¹: Fédération Internationale de Football Association (FIFA) @ Wikipedia

²: Northern Cyprus (TRNC) has a four-letter FIFA country code

Find Out More

References

Questions? Comments?

Join us over on the r/PlanetRuby channel. Official home of the Best of Ruby Gems Series discussions. Thanks!

Built with Ruby (running Jekyll) on 2021-07-25 15:15:02 +0000 in 0.371 seconds.
Hosted on GitHub Pages. </> Source on GitHub. (0) Dedicated to the public domain.