Class: SportDb::Sync::Team

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/readers/sync/more.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?



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

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



35
# File 'lib/sportdb/readers/sync/more.rb', line 35

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

.find_or_create(team_or_teams) ⇒ Object



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

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