Written by 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)?
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
[#<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
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 ...
The World’s Football Association / Governing Body
uses its own country list and (three-letter²) codes - see
the List of FIFA country codes @ Wikipedia
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:
²: Northern Cyprus (TRNC) has a four-letter FIFA country code
Join us over on the r/PlanetRuby channel. Official home of the Best of Ruby Gems Series discussions. Thanks!