class SportDb::Sync::NationalTeam

Public Class Methods

find_or_create( team ) click to toggle source
# File lib/sportdb/sync/sync.rb, line 8
def self.find_or_create( team )
  rec = Model::Team.find_by( name: team.name )
  if rec.nil?
    puts "add national team: #{team.key}, #{team.name}, #{team.country.name} (#{team.country.key})"

    ### note: key expected three or more lowercase letters a-z /\A[a-z]{3,}\z/
    attribs = {
      key:        team.key,   ## note: always use downcase fifa code for now!!!
      name:       team.name,
      code:       team.code,
      country_id: Sync::Country.find_or_create( team.country ).id,
      club:       false,
      national:   true  ## check -is default anyway - use - why? why not?
    }

    if team.alt_names.empty? == false
      attribs[:alt_names] = team.alt_names.join('|')
    end

    rec = Model::Team.create!( attribs )
  end
  rec
end