Class: SportDb::Import::Configuration

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

Constant Summary collapse

CLUBS_REGEX =
%r{  (?:^|/)               # beginning (^) or beginning of path (/)
    (?:[a-z]{1,3}\.)?   # optional country code/key e.g. eng.clubs.txt
    clubs\.txt$
}x
CLUBS_WIKI_REGEX =
%r{  (?:^|/)               # beginning (^) or beginning of path (/)
    (?:[a-z]{1,3}\.)?   # optional country code/key e.g. eng.clubs.wiki.txt
   clubs\.wiki\.txt$
}x

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clubs_dirObject

todo/fix: find a better way to configure club / team datasets



33
34
35
# File 'lib/sportdb/config/config.rb', line 33

def clubs_dir
  @clubs_dir
end

Class Method Details

.find_datafiles(path, pattern) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sportdb/config/config.rb', line 49

def self.find_datafiles( path, pattern )
   datafiles = []   ## note: [country, path] pairs for now

   ## check all txt files as candidates  (MUST include country code for now)
   candidates = Dir.glob( "#{path}/**/*.txt" )
   pp candidates
   candidates.each do |candidate|
     datafiles << candidate    if pattern.match( candidate )
   end

   pp datafiles
   datafiles
end

.find_datafiles_clubs(path) ⇒ Object



62
# File 'lib/sportdb/config/config.rb', line 62

def self.find_datafiles_clubs( path )       find_datafiles( path, CLUBS_REGEX ); end

.find_datafiles_clubs_wiki(path) ⇒ Object



63
# File 'lib/sportdb/config/config.rb', line 63

def self.find_datafiles_clubs_wiki( path )  find_datafiles( path, CLUBS_WIKI_REGEX ); end

Instance Method Details

#build_club_indexObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/sportdb/config/config.rb', line 66

def build_club_index
    ## unify team names; team (builtin/known/shared) name mappings
    ## cleanup team names - use local ("native") name with umlaut etc.
    ## todo/fix: add to teamreader
    ##              check that name and alt_names for a club are all unique (not duplicates)

    clubs = ClubIndex.build( clubs_dir )
    if clubs.errors?
      puts ""
      puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
      puts " #{clubs.errors.size} errors:"
      pp clubs.errors
      ## exit 1
    end

    clubs
end

#build_country_indexObject

todo/check: rename to setup_country_index or read_country_index - why? why not?



20
21
22
# File 'lib/sportdb/config/config.rb', line 20

def build_country_index    ## todo/check: rename to setup_country_index or read_country_index - why? why not?
  CountryIndex.new( Fifa.countries )
end

#clubsObject



26
27
28
29
# File 'lib/sportdb/config/config.rb', line 26

def clubs
  @clubs  ||= build_club_index
  @clubs
end

#countriesObject

todo/check: rename to country_mappings/index - why? why not?

or countries_by_code or countries_by_key


15
16
17
18
# File 'lib/sportdb/config/config.rb', line 15

def countries
  @countries ||= build_country_index
  @countries
end

#leaguesObject



87
88
89
90
# File 'lib/sportdb/config/config.rb', line 87

def leagues
  read_leagues()      if @leagues.nil?
  @leagues
end

#read_leaguesObject



92
93
94
95
96
97
98
# File 'lib/sportdb/config/config.rb', line 92

def read_leagues
  #####
  # add / read-in leagues config
  @leagues = LeagueConfig.new

  self  ## return self for chaining
end