Class: Fifa::CountryIndex::OrgIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/fifa/org_index.rb

Overview

change to MemberIndex or AssocIndex or such - why? why not?

Constant Summary collapse

ALT_KEYS =
{
  'world'  => 'fifa',
  'europe' => 'uefa',    #=> Union of European Football Associations
  'northamericacentralamericacaribbean' => 'concacaf',  #=> Confederation of North, Central American and Caribbean Association Football
  'northcentralamericacaribbean'        => 'concacaf',  ## e.g. North & Central America and the Caribbean
  'northamerica' => 'nafu',  # => North American Football Union
  'centralamerica' => 'uncaf',  #=> Unión Centroamericana de Fútbol
  'caribbean' => 'cfu',  #=> Caribbean Football Union
  'africa' => 'caf',      # => Confédération Africaine de Football
  'eastcentralafrica' => 'cecafa',  # => Council for East and Central Africa Football Associations
  'southernafrica' => 'cosafa',   # => Council of Southern Africa Football Associations
  'westafrica' => 'wafu',         # => West African Football Union/Union du Football de l'Ouest Afrique
  'northafrica' => 'unaf',        # => Union of North African Federations
  'centralafrica' => 'uniffac',  # => Union des Fédérations du Football de l'Afrique Centrale
  'asia'   => 'afc',      # => Asian Football Confederation
  'middleeast' => 'waff', # => West Asian Football Federation  -- note: excludes Iran and Israel
  'eastasia'   => 'eaff',
  'centralasia' => 'cafa',
  'southasia' => 'saff',
  'southeastasia' => 'aff',
  'oceania'    => 'ofc',  # =>  Oceania Football Confederation
  'pacific'    => 'ofc',
  'southamerica' => 'conmebol',  #=>  Confederación Sudamericana de Fútbol
}

Instance Method Summary collapse

Constructor Details

#initialize(countries = nil) ⇒ OrgIndex

Returns a new instance of OrgIndex.



33
34
35
36
37
# File 'lib/fifa/org_index.rb', line 33

def initialize( countries=nil )
    @orgs = {}   ## countries by org (key)

    add( countries )  if countries
end

Instance Method Details

#_norm_org(name) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/fifa/org_index.rb', line 64

def _norm_org( name )
  ## remove space, comma, ampersand (&) and words: and, the
  name.gsub( /  [ ,&] |
               \band\b |
               \bthe\b
             /x, '' )
end

#add(countries) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/fifa/org_index.rb', line 39

def add( countries )
    countries.each do |country|
        ## note: assumes all tags are sport / fifa tags for now
        country.tags.each do |tag|
          @orgs[ tag ] ||= []
          @orgs[ tag ] << country
        end
     end
end

#keysObject



50
# File 'lib/fifa/org_index.rb', line 50

def keys() @orgs.keys; end

#members(key = :fifa) ⇒ Object

default to fifa members



52
53
54
55
56
57
58
59
60
61
# File 'lib/fifa/org_index.rb', line 52

def members( key=:fifa )   ## default to fifa members
  key       = key.to_s.downcase
  countries = @orgs[ key ]

  if countries.nil?    ## (re)try / check with alternative (convenience) org name
    alt_key = ALT_KEYS[ _norm_org( key ) ]
    countries = @orgs[ alt_key ]   if alt_key
  end
  countries
end