Class: SportDb::Import::TeamIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/formats/team/team_index.rb

Instance Method Summary collapse

Instance Method Details

#__find_by!(name:, league:, mods: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sportdb/formats/team/team_index.rb', line 24

def __find_by!( name:, league:, mods: nil )
  if mods && mods[ league.key ] && mods[ league.key ][ name ]
    mods[ league.key ][ name ]
  else
    if league.clubs?
      if league.intl?    ## todo/fix: add intl? to ActiveRecord league!!!
        catalog.clubs.find!( name )
      else  ## assume clubs in domestic/national league tournament
        catalog.clubs.find_by!( name: name, country: league.country )
      end
    else   ## assume national teams (not clubs)
      catalog.national_teams.find!( name )
    end
  end
end

#catalogObject

note: “virtual” index lets you search clubs and/or national_teams (don’t care)



9
# File 'lib/sportdb/formats/team/team_index.rb', line 9

def catalog() Import.catalog; end

#find_by!(name:, league:, mods: nil) ⇒ Object

todo/check: rename to/use map_by! for array version - why? why not?



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sportdb/formats/team/team_index.rb', line 12

def find_by!( name:, league:, mods: nil )
  if name.is_a?( Array )
    recs = []
    name.each do |q|
      recs << __find_by!( name: q, league: league, mods: mods )
    end
    recs
  else  ## assume single name
    __find_by!( name: name, league: league, mods: mods )
  end
end