class SportDb::Sync::Country

Public Class Methods

country( q ) click to toggle source

todo/fix: add ALTERNATE / ALTERNATIVE COUNTRY KEYS!!!!

e.g. d => de, a => at, en => eng, etc.
plus  add all fifa codes too   aut => at, etc.  - why? why not?
# File lib/sportdb/sync/country.rb, line 10
def self.country( q )
   ## note: use built-in countries for mapping country keys/codes
   country = Import.catalog.countries.find( q )
   if country
    ## todo/check:  keep key mapping warning - useful? why? why not?
     if country.key != q.to_s
      puts "** note: mapping (normalizing) country key >#{q}< to >#{country.key}<"
     end
   else
     puts "** !!! ERROR !!! unknown / invalid country for key >#{q}<; sorry - add to COUNTRIES table"
     exit 1
   end
   country
end
find( country ) click to toggle source

finders

# File lib/sportdb/sync/country.rb, line 41
def self.find( country )
  WorldDb::Model::Country.find_by( key: country.key )
end
find!( country ) click to toggle source
# File lib/sportdb/sync/country.rb, line 45
 def self.find!( country )
   rec = find( country )
   if rec.nil?
       puts "** !!! ERROR !!! - country for key >#{country.key}< not found; sorry - add to COUNTRIES table"
       exit 1
   end
   rec
end
find_or_create( country ) click to toggle source
# File lib/sportdb/sync/country.rb, line 54
 def self.find_or_create( country )
  rec = find( country )
  if rec.nil?
    attribs = {
      key:  country.key,
      name: country.name,
      code: country.code,  ## fix:  uses fifa code now (should be iso-alpha3 if available)
      ## fifa: country.fifa,
      area: 1,
      pop:  1
    }
    rec = WorldDb::Model::Country.create!( attribs )
  end
  rec
end
search!( q ) click to toggle source

searchers

# File lib/sportdb/sync/country.rb, line 28
def self.search!( q )
  country = country( q )
  find!( country )
end
search_or_create!( q ) click to toggle source
# File lib/sportdb/sync/country.rb, line 33
def self.search_or_create!( q )
  country = country( q )
  find_or_create( country )
end