Class: SportDb::Sync::Team

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/sync/sync.rb

Class Method Summary collapse

Class Method Details

.__find_or_create(team) ⇒ Object

todo/check: use find_or_create_worker instead of _find - why? why not?



52
53
54
55
56
57
58
59
60
# File 'lib/sportdb/sync/sync.rb', line 52

def self.__find_or_create( team )  ## todo/check: use find_or_create_worker instead of _find - why? why not?
   rec = if team.is_a?( Import::NationalTeam )
           NationalTeam.find_or_create( team )
         else ## assume Club
           Club.find_or_create( team )
         end
   cache[ team.name ] = rec    ## note: assume "canonical" unique team name
   rec
end

.cacheObject

auto-cache all clubs by find_or_create for later mapping / lookup



36
# File 'lib/sportdb/sync/sync.rb', line 36

def self.cache() @cache ||= {}; end

.find_or_create(team_or_teams) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sportdb/sync/sync.rb', line 38

def self.find_or_create( team_or_teams )
  if team_or_teams.is_a?( Array )
    recs = []
    teams = team_or_teams
    teams.each do |team|
      recs << __find_or_create( team )
    end
    recs
  else  # assome single rec
    team = team_or_teams
    __find_or_create( team )
  end
end