Class: Fifa::CountryIndex

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

Overview

built-in countries for (quick starter) auto-add

Defined Under Namespace

Classes: OrgIndex

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recs = nil) ⇒ CountryIndex

Returns a new instance of CountryIndex.



17
18
19
20
21
22
23
# File 'lib/fifa/country_index.rb', line 17

def initialize( recs=nil )
  @countries  = []
  @by_code    = {}  ## countries by codes (fifa, internet, etc)
  @orgs       = OrgIndex.new

  add( recs )   if recs
end

Class Method Details

.read(*paths) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/fifa/country_index.rb', line 8

def self.read( *paths )
  recs = []
  paths.each do |path|
    recs += CountryReader.read( path )
  end
  new( recs )
end

Instance Method Details

#_add(recs) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fifa/country_index.rb', line 56

def _add( recs )
  recs.each do |rec|
    key = rec.code.downcase    ## add codes lookups - key, fifa, ...
    if @by_code[ key ]
      puts "** !!! ERROR !!! country code (fifa)  >#{rec.code}< already exits!!"
      exit 1
    else
      @by_code[ key ] = rec
    end
  end
end

#add(recs) ⇒ Object



48
49
50
51
52
53
# File 'lib/fifa/country_index.rb', line 48

def add( recs )
  @countries += recs

  _add( recs)              ## step one add to our own index
  @orgs.add( recs )   ## step two add to orgs (helper) index (for members)
end

#countriesObject



25
# File 'lib/fifa/country_index.rb', line 25

def countries() @countries; end

#each(&blk) ⇒ Object



27
# File 'lib/fifa/country_index.rb', line 27

def each( &blk ) @countries.each { |country| blk.call( country ) }; end

#find(q) ⇒ Object Also known as: []



40
41
42
43
# File 'lib/fifa/country_index.rb', line 40

def find( q )
  key = q.to_s.downcase   ## allow symbols (and always downcase e.g. AUT to aut etc.)
  @by_code[ key ]
end

#members(key = :fifa) ⇒ Object

default to fifa members



31
32
33
# File 'lib/fifa/country_index.rb', line 31

def members( key=:fifa )   ## default to fifa members
  @orgs.members( key )
end

#orgsObject

for testing/debugging return org keys

return OrgIndex instead - why? why not?


37
# File 'lib/fifa/country_index.rb', line 37

def orgs() @orgs.keys; end

#sizeObject



26
# File 'lib/fifa/country_index.rb', line 26

def size()  @countries.size; end