sportdb-config 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Manifest.txt +2 -43
- data/lib/sportdb/config/config.rb +72 -7
- data/lib/sportdb/config/league.rb +1 -1
- data/lib/sportdb/config/league_reader.rb +3 -3
- data/lib/sportdb/config/team_reader.rb +90 -59
- data/lib/sportdb/config/version.rb +2 -2
- data/test/test_config.rb +2 -0
- data/test/test_league_reader.rb +54 -0
- data/test/test_league_utils.rb +0 -44
- data/test/test_team_reader.rb +56 -0
- metadata +4 -88
- data/config/teams/al.txt +0 -6
- data/config/teams/at.txt +0 -26
- data/config/teams/be.txt +0 -58
- data/config/teams/bg.txt +0 -6
- data/config/teams/by.txt +0 -5
- data/config/teams/ca.txt +0 -4
- data/config/teams/ch.txt +0 -10
- data/config/teams/cy.txt +0 -7
- data/config/teams/cz.txt +0 -6
- data/config/teams/de.txt +0 -129
- data/config/teams/dk.txt +0 -6
- data/config/teams/eng.txt +0 -294
- data/config/teams/es.txt +0 -148
- data/config/teams/fi.txt +0 -6
- data/config/teams/fr.txt +0 -98
- data/config/teams/ga.txt +0 -5
- data/config/teams/gr.txt +0 -87
- data/config/teams/hr.txt +0 -9
- data/config/teams/hu.txt +0 -5
- data/config/teams/ie.txt +0 -5
- data/config/teams/is.txt +0 -6
- data/config/teams/it.txt +0 -99
- data/config/teams/lu.txt +0 -6
- data/config/teams/mc.txt +0 -4
- data/config/teams/md.txt +0 -4
- data/config/teams/mt.txt +0 -6
- data/config/teams/mx.txt +0 -30
- data/config/teams/nir.txt +0 -6
- data/config/teams/nl.txt +0 -45
- data/config/teams/no.txt +0 -7
- data/config/teams/pl.txt +0 -6
- data/config/teams/pt.txt +0 -53
- data/config/teams/ro.txt +0 -5
- data/config/teams/rs.txt +0 -6
- data/config/teams/ru.txt +0 -5
- data/config/teams/sco.txt +0 -73
- data/config/teams/se.txt +0 -6
- data/config/teams/si.txt +0 -5
- data/config/teams/sk.txt +0 -5
- data/config/teams/tr.txt +0 -39
- data/config/teams/ua.txt +0 -5
- data/config/teams/us.txt +0 -44
- data/config/teams/wal.txt +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57dbbed1c0fa0fe8269db547f5d91a946ef31e88
|
4
|
+
data.tar.gz: cac09dc10a2f4066cca23beabf3e77826a7a4109
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f15a2cdd5ed88333c6acfa9c5416ef63eeadf1c0b7e67f2239767f3d17cbe65f16870cbea1818f331e6fbaefe368b432eb4e933b7d4c107d9553ef627345d8b
|
7
|
+
data.tar.gz: bbe5c4bbef53f5ec3708d2392fa6447a6be28db560c82c74a31df2ec0a65acf2eed5207823e652bfd0cf030f504eb70c9b5e9f29c18cac44a3a2a3a9a9a8bba7
|
data/Manifest.txt
CHANGED
@@ -7,49 +7,6 @@ config/leagues/eng.txt
|
|
7
7
|
config/leagues/fr.txt
|
8
8
|
config/leagues/gr.txt
|
9
9
|
config/leagues/sco.txt
|
10
|
-
config/teams/al.txt
|
11
|
-
config/teams/at.txt
|
12
|
-
config/teams/be.txt
|
13
|
-
config/teams/bg.txt
|
14
|
-
config/teams/by.txt
|
15
|
-
config/teams/ca.txt
|
16
|
-
config/teams/ch.txt
|
17
|
-
config/teams/cy.txt
|
18
|
-
config/teams/cz.txt
|
19
|
-
config/teams/de.txt
|
20
|
-
config/teams/dk.txt
|
21
|
-
config/teams/eng.txt
|
22
|
-
config/teams/es.txt
|
23
|
-
config/teams/fi.txt
|
24
|
-
config/teams/fr.txt
|
25
|
-
config/teams/ga.txt
|
26
|
-
config/teams/gr.txt
|
27
|
-
config/teams/hr.txt
|
28
|
-
config/teams/hu.txt
|
29
|
-
config/teams/ie.txt
|
30
|
-
config/teams/is.txt
|
31
|
-
config/teams/it.txt
|
32
|
-
config/teams/lu.txt
|
33
|
-
config/teams/mc.txt
|
34
|
-
config/teams/md.txt
|
35
|
-
config/teams/mt.txt
|
36
|
-
config/teams/mx.txt
|
37
|
-
config/teams/nir.txt
|
38
|
-
config/teams/nl.txt
|
39
|
-
config/teams/no.txt
|
40
|
-
config/teams/pl.txt
|
41
|
-
config/teams/pt.txt
|
42
|
-
config/teams/ro.txt
|
43
|
-
config/teams/rs.txt
|
44
|
-
config/teams/ru.txt
|
45
|
-
config/teams/sco.txt
|
46
|
-
config/teams/se.txt
|
47
|
-
config/teams/si.txt
|
48
|
-
config/teams/sk.txt
|
49
|
-
config/teams/tr.txt
|
50
|
-
config/teams/ua.txt
|
51
|
-
config/teams/us.txt
|
52
|
-
config/teams/wal.txt
|
53
10
|
lib/sportdb/config.rb
|
54
11
|
lib/sportdb/config/config.rb
|
55
12
|
lib/sportdb/config/league.rb
|
@@ -61,5 +18,7 @@ lib/sportdb/config/utils/season_utils.rb
|
|
61
18
|
lib/sportdb/config/version.rb
|
62
19
|
test/helper.rb
|
63
20
|
test/test_config.rb
|
21
|
+
test/test_league_reader.rb
|
64
22
|
test/test_league_utils.rb
|
65
23
|
test/test_season_utils.rb
|
24
|
+
test/test_team_reader.rb
|
@@ -6,20 +6,82 @@ module SportDb
|
|
6
6
|
|
7
7
|
class Configuration
|
8
8
|
|
9
|
-
attr_accessor :team_mappings
|
10
|
-
attr_accessor :teams
|
11
9
|
|
12
|
-
|
10
|
+
def team_mappings
|
11
|
+
read_teams() if @team_mappings.nil?
|
12
|
+
@team_mappings
|
13
|
+
end
|
13
14
|
|
15
|
+
def teams
|
16
|
+
read_teams() if @teams.nil?
|
17
|
+
@teams
|
18
|
+
end
|
14
19
|
|
20
|
+
def leagues
|
21
|
+
read_leagues() if @leagues.nil?
|
22
|
+
@leagues
|
23
|
+
end
|
15
24
|
|
16
|
-
def initialize
|
17
25
|
|
26
|
+
####
|
27
|
+
# todo/fix: find a better way to configure club / team datasets
|
28
|
+
attr_accessor :clubs_dir
|
29
|
+
|
30
|
+
def clubs_dir() @clubs_dir ||= './clubs'; end
|
31
|
+
|
32
|
+
CLUBS_DATAFILES = { ## path by country to clubs.txt
|
33
|
+
de: 'europe/de-deutschland',
|
34
|
+
fr: 'europe/fr-france',
|
35
|
+
mc: 'europe/mc-monaco',
|
36
|
+
es: 'europe/es-espana',
|
37
|
+
it: 'europe/it-italy',
|
38
|
+
pt: 'europe/pt-portugal',
|
39
|
+
nl: 'europe/nl-netherlands',
|
40
|
+
be: 'europe/be-belgium',
|
41
|
+
tr: 'europe/tr-turkey',
|
42
|
+
gr: 'europe/gr-greece',
|
43
|
+
eng: 'europe/eng-england',
|
44
|
+
wal: 'europe/wal-wales',
|
45
|
+
sco: 'europe/sco-scotland',
|
46
|
+
nir: 'europe/nir-northern-ireland',
|
47
|
+
at: 'europe/at-austria',
|
48
|
+
al: 'europe/al-albania',
|
49
|
+
bg: 'europe/bg-bulgaria',
|
50
|
+
by: 'europe/by-belarus',
|
51
|
+
ch: 'europe/ch-confoederatio-helvetica',
|
52
|
+
cy: 'europe/cy-cyprus',
|
53
|
+
cz: 'europe/cz-czech-republic',
|
54
|
+
dk: 'europe/dk-denmark',
|
55
|
+
fi: 'europe/fi-finland',
|
56
|
+
ge: 'europe/ge-georgia',
|
57
|
+
hr: 'europe/hr-croatia',
|
58
|
+
hu: 'europe/hu-hungary',
|
59
|
+
ie: 'europe/ie-ireland',
|
60
|
+
is: 'europe/is-iceland',
|
61
|
+
lu: 'europe/lu-luxembourg',
|
62
|
+
md: 'europe/md-moldova',
|
63
|
+
mt: 'europe/mt-malta',
|
64
|
+
no: 'europe/no-norway',
|
65
|
+
pl: 'europe/pl-poland',
|
66
|
+
ro: 'europe/ro-romania',
|
67
|
+
rs: 'europe/rs-serbia',
|
68
|
+
ru: 'europe/ru-russia',
|
69
|
+
se: 'europe/se-sweden',
|
70
|
+
si: 'europe/si-slovenia',
|
71
|
+
sk: 'europe/sk-slovakia',
|
72
|
+
ua: 'europe/ua-ukraine',
|
73
|
+
mx: 'north-america/mx-mexico',
|
74
|
+
us: 'north-america/us-united-states',
|
75
|
+
ca: 'north-america/ca-canada' }
|
76
|
+
|
77
|
+
def read_teams
|
18
78
|
## unify team names; team (builtin/known/shared) name mappings
|
19
79
|
## cleanup team names - use local ("native") name with umlaut etc.
|
20
80
|
recs = []
|
21
|
-
|
22
|
-
|
81
|
+
|
82
|
+
## todo/fix: pass along / use country code too
|
83
|
+
CLUBS_DATAFILES.each do |country, path|
|
84
|
+
recs += TeamReader.read( "#{clubs_dir}/#{path}/clubs.txt" )
|
23
85
|
end
|
24
86
|
|
25
87
|
############################
|
@@ -47,12 +109,14 @@ class Configuration
|
|
47
109
|
@teams[ rec.name ] = rec
|
48
110
|
end
|
49
111
|
|
112
|
+
self ## return self for chaining
|
113
|
+
end
|
50
114
|
|
115
|
+
def read_leagues
|
51
116
|
#####
|
52
117
|
# add / read-in leagues config
|
53
118
|
@leagues = LeagueConfig.new
|
54
119
|
|
55
|
-
|
56
120
|
self ## return self for chaining
|
57
121
|
end
|
58
122
|
end # class Configuration
|
@@ -60,6 +124,7 @@ end # class Configuration
|
|
60
124
|
|
61
125
|
|
62
126
|
|
127
|
+
|
63
128
|
## lets you use
|
64
129
|
## SportDb::Import.configure do |config|
|
65
130
|
## config.hello = 'World'
|
@@ -51,7 +51,7 @@ def initialize
|
|
51
51
|
pp @leagues_history
|
52
52
|
|
53
53
|
%w(eng sco fr gr).each do |country|
|
54
|
-
hash = LeagueReader.
|
54
|
+
hash = LeagueReader.read( "#{Boot.data_dir}/leagues/#{country}.txt" )
|
55
55
|
pp hash
|
56
56
|
|
57
57
|
hash.each do |season,league_hash|
|
@@ -6,9 +6,9 @@ module SportDb
|
|
6
6
|
|
7
7
|
class LeagueReader
|
8
8
|
|
9
|
-
def self.
|
9
|
+
def self.read( path )
|
10
10
|
txt = File.open( path, 'r:utf-8' ).read
|
11
|
-
|
11
|
+
parse( txt )
|
12
12
|
end
|
13
13
|
|
14
14
|
|
@@ -20,7 +20,7 @@ SEASON_REGEX = /\[
|
|
20
20
|
)
|
21
21
|
\]/x
|
22
22
|
|
23
|
-
def self.
|
23
|
+
def self.parse( txt )
|
24
24
|
hash = {}
|
25
25
|
season = '*' ## use '*' for default/latest season
|
26
26
|
|
@@ -7,69 +7,113 @@ module Import
|
|
7
7
|
|
8
8
|
class TeamReader
|
9
9
|
|
10
|
+
##
|
11
|
+
# note: use our own (internal) team struct for now - why? why not?
|
12
|
+
class Team
|
13
|
+
## todo: use just names for alt_names - why? why not?
|
14
|
+
attr_accessor :name, :alt_names, :year, :ground, :city
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@alt_names = []
|
18
|
+
end
|
19
|
+
end # class Team
|
20
|
+
|
21
|
+
|
10
22
|
|
11
|
-
def self.
|
23
|
+
def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not?
|
12
24
|
txt = File.open( path, 'r:utf-8' ).read
|
13
|
-
|
25
|
+
parse( txt )
|
14
26
|
end
|
15
27
|
|
16
28
|
|
17
|
-
def self.
|
29
|
+
def self.parse( txt )
|
18
30
|
recs = []
|
31
|
+
last_rec = nil
|
32
|
+
|
19
33
|
txt.each_line do |line|
|
20
34
|
line = line.strip
|
21
35
|
|
22
36
|
next if line.empty?
|
23
37
|
next if line.start_with?( '#' ) ## skip comments too
|
24
38
|
|
25
|
-
## strip inline comments too
|
39
|
+
## strip inline (until end-of-line) comments too
|
26
40
|
## e.g Eupen => KAS Eupen, ## [de]
|
27
41
|
## => Eupen => KAS Eupen,
|
28
42
|
line = line.sub( /#.*/, '' ).strip
|
29
|
-
|
30
43
|
pp line
|
31
|
-
names_line, team_line = line.split( '=>' )
|
32
44
|
|
33
|
-
names = names_line.split( /[|,]/ ) # team names - allow comma(,) or pipe(|)
|
34
|
-
team = team_line.split( ',' ) # (canoncial) team name, team_city
|
35
|
-
|
36
|
-
## remove leading and trailing spaces
|
37
|
-
names = names.map { |name| name.strip }
|
38
|
-
team = team.map { |team| team.strip }
|
39
|
-
pp names
|
40
|
-
pp team
|
41
|
-
|
42
|
-
canonical_name = team[0]
|
43
|
-
city = team[1]
|
44
|
-
|
45
|
-
## squish (white)spaces
|
46
|
-
# e.g. New York FC (2011-) => New York FC (2011-)
|
47
|
-
# e.g. León › Guanajuato => León › Guanajuato
|
48
|
-
canonical_name = canonical_name.gsub( /[ \t]+/, ' ' )
|
49
|
-
city = city.gsub( /[ \t]+/, ' ' ) if city
|
50
|
-
|
51
|
-
## note:
|
52
|
-
## check/todo!!!!!!!!!!!!!!!!!-
|
53
|
-
## strip year if to present e.g. (2011-)
|
54
|
-
##
|
55
|
-
## do NOT strip for defunct / historic clubs e.g.
|
56
|
-
## (1899-1910)
|
57
|
-
## or (-1914) or (-2011) etc.
|
58
45
|
|
46
|
+
if line.start_with?( '|' )
|
47
|
+
## assume continuation with line of alternative names
|
48
|
+
## note: skip leading pipe
|
49
|
+
values = line[1..-1].split( '|' ) # team names - allow/use pipe(|)
|
50
|
+
## strip and squish (white)spaces
|
51
|
+
# e.g. New York FC (2011-) => New York FC (2011-)
|
52
|
+
values = values.map { |value| value.strip.gsub( /[ \t]+/, ' ' ) }
|
53
|
+
last_rec.alt_names += values
|
54
|
+
|
55
|
+
## check for duplicates - simple check for now - fix/improve
|
56
|
+
## todo/fix: (auto)remove duplicates - why? why not?
|
57
|
+
count = last_rec.alt_names.size
|
58
|
+
count_uniq = last_rec.alt_names.uniq.size
|
59
|
+
if count != count_uniq
|
60
|
+
puts
|
61
|
+
puts "*** !!! WARN !!! - #{count-count_uniq} duplicate alt name(s):"
|
62
|
+
pp last_rec
|
63
|
+
## exit 1
|
64
|
+
end
|
65
|
+
else
|
66
|
+
values = line.split( ',' )
|
67
|
+
|
68
|
+
rec = Team.new
|
69
|
+
value = values.shift ## get first item
|
70
|
+
## strip and squish (white)spaces
|
71
|
+
# e.g. New York FC (2011-) => New York FC (2011-)
|
72
|
+
value = value.strip.gsub( /[ \t]+/, ' ' )
|
73
|
+
rec.name = value # canoncial_name
|
74
|
+
|
75
|
+
## note:
|
76
|
+
## check/todo!!!!!!!!!!!!!!!!!-
|
77
|
+
## strip year if to present e.g. (2011-)
|
78
|
+
##
|
79
|
+
## do NOT strip for defunct / historic clubs e.g.
|
80
|
+
## (1899-1910)
|
81
|
+
## or (-1914) or (-2011) etc.
|
82
|
+
|
83
|
+
###
|
84
|
+
## todo: move year out of canonical team name - why? why not?
|
85
|
+
|
86
|
+
## check if canonical name include (2011-) or similar in name
|
87
|
+
## if yes, remove (2011-) and add to (alt) names
|
88
|
+
## e.g. New York FC (2011) => New York FC
|
89
|
+
if rec.name =~ /\(.+?\)/ ## note: use non-greedy (?) match
|
90
|
+
name = rec.name.gsub( /\(.+?\)/, '' ).strip
|
91
|
+
rec.alt_names << name
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
## todo/check - check for unknown format values
|
96
|
+
## e.g. too many values, duplicate years, etc.
|
97
|
+
## check for overwritting, etc.
|
98
|
+
while values.size > 0
|
99
|
+
value = values.shift
|
100
|
+
## strip and squish (white)spaces
|
101
|
+
# e.g. León › Guanajuato => León › Guanajuato
|
102
|
+
value = value.strip.gsub( /[ \t]+/, ' ' )
|
103
|
+
if value =~/^\d{4}$/ # e.g 1904
|
104
|
+
rec.year = value.to_i
|
105
|
+
elsif value.start_with?( '@' ) # e.g. @ Anfield
|
106
|
+
## cut-off leading @ and spaces
|
107
|
+
rec.ground = value[1..-1].strip
|
108
|
+
else
|
109
|
+
## assume city / geo tree
|
110
|
+
rec.city = value
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
last_rec = rec
|
59
115
|
|
60
116
|
|
61
|
-
###
|
62
|
-
## todo: move year out of canonical team name - why? why not?
|
63
|
-
##
|
64
|
-
|
65
|
-
## check if canonical name include (2011-) or similar in name
|
66
|
-
## if yes, remove (2011-) and add to (alt) names
|
67
|
-
## e.g. New York FC (2011) => New York FC
|
68
|
-
if canonical_name =~ /\(.+?\)/ ## note: use non-greedy (?) match
|
69
|
-
name = canonical_name.gsub( /\(.+?\)/, '' ).strip
|
70
|
-
names << name
|
71
|
-
end
|
72
|
-
|
73
117
|
### todo/fix:
|
74
118
|
## auto-add alt name with dots stripped - why? why not?
|
75
119
|
## e.g. D.C. United => DC United
|
@@ -83,22 +127,9 @@ def self.read( txt ) ## rename to parse - why? why not? and use read for file
|
|
83
127
|
## always strip (2011-) !!!
|
84
128
|
## always strip dots (e.g. St., F.C, etc.)
|
85
129
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
## note: remove from alt_names if canonical name (mapping 1:1)
|
90
|
-
## or if empty
|
91
|
-
alt_names = names.select {|name| (name.empty? || name == canonical_name) ? false : true }
|
92
|
-
|
93
|
-
## todo: add country (code) too!!!
|
94
|
-
rec = SportDb::Struct::Team.create(
|
95
|
-
name: canonical_name,
|
96
|
-
city: city, ## note: team_city is optional for now (might be nil!!!)
|
97
|
-
alt_names: alt_names
|
98
|
-
)
|
99
|
-
## pp rec
|
100
|
-
recs << rec
|
101
|
-
end
|
130
|
+
recs << rec
|
131
|
+
end
|
132
|
+
end # each_line
|
102
133
|
recs
|
103
134
|
end # method read
|
104
135
|
end # class TeamReader
|
@@ -7,8 +7,8 @@ module Boot ## note: use a different module than Config to avoid confusion
|
|
7
7
|
## maybe rename later gem itself to sportdb-boot - why? why not?
|
8
8
|
|
9
9
|
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
10
|
-
MINOR =
|
11
|
-
PATCH =
|
10
|
+
MINOR = 1
|
11
|
+
PATCH = 0
|
12
12
|
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
13
13
|
|
14
14
|
def self.version
|
data/test/test_config.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_league_reader.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestLeagueReader < MiniTest::Test
|
11
|
+
|
12
|
+
def test_parse_eng
|
13
|
+
|
14
|
+
hash = SportDb::Import::LeagueReader.parse( <<TXT )
|
15
|
+
1 => premierleague, English Premier League
|
16
|
+
2 => championship, English Championship League
|
17
|
+
3 => league1, English League 1
|
18
|
+
4 => league2, English League 2
|
19
|
+
5 => conference, English Conference
|
20
|
+
|
21
|
+
#########################################
|
22
|
+
# until (including) 2003-04 season
|
23
|
+
|
24
|
+
[2003-04] # or just use 2003-04: or similar - why? why not?
|
25
|
+
# or use 2003/04 - 1992/93 - why? why not?
|
26
|
+
|
27
|
+
1 => premierleague, English Premier League
|
28
|
+
2 => division1, English Division 1
|
29
|
+
3 => division2, English Division 2
|
30
|
+
4 => division3, English Division 3
|
31
|
+
|
32
|
+
|
33
|
+
#############################################
|
34
|
+
# note: in season 1992/93 the premier league starts
|
35
|
+
# until (including) 1991-92} season
|
36
|
+
|
37
|
+
[1991-92]
|
38
|
+
1 => division1, English Division 1
|
39
|
+
2 => division2, English Division 2
|
40
|
+
3 => division3, English Division 3
|
41
|
+
3a => division3n, English Division 3 (North)
|
42
|
+
3b => division3s, English Division 3 (South)
|
43
|
+
4 => division4, English Division 4 ## check if real?
|
44
|
+
TXT
|
45
|
+
|
46
|
+
|
47
|
+
assert_equal 'premierleague', hash['*']['1']
|
48
|
+
assert_equal 'championship', hash['*']['2']
|
49
|
+
assert_equal 'league1', hash['*']['3']
|
50
|
+
|
51
|
+
assert_equal 'division1', hash['1991-92']['1']
|
52
|
+
assert_equal 'division2', hash['1991-92']['2']
|
53
|
+
end # method test_parse_eng
|
54
|
+
end # class TestLeagueUtils
|
data/test/test_league_utils.rb
CHANGED
@@ -43,48 +43,4 @@ class TestLeagueUtils < MiniTest::Test
|
|
43
43
|
assert_equal '1-alphaethniki', LeagueUtils.basename( '1', country: 'gr', season: '2005-06' )
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
def test_read_txt
|
49
|
-
|
50
|
-
hash = SportDb::Import::LeagueReader.read( <<TXT)
|
51
|
-
1 => premierleague, English Premier League
|
52
|
-
2 => championship, English Championship League
|
53
|
-
3 => league1, English League 1
|
54
|
-
4 => league2, English League 2
|
55
|
-
5 => conference, English Conference
|
56
|
-
|
57
|
-
#########################################
|
58
|
-
# until (including) 2003-04 season
|
59
|
-
|
60
|
-
[2003-04] # or just use 2003-04: or similar - why? why not?
|
61
|
-
# or use 2003/04 - 1992/93 - why? why not?
|
62
|
-
|
63
|
-
1 => premierleague, English Premier League
|
64
|
-
2 => division1, English Division 1
|
65
|
-
3 => division2, English Division 2
|
66
|
-
4 => division3, English Division 3
|
67
|
-
|
68
|
-
|
69
|
-
#############################################
|
70
|
-
# note: in season 1992/93 the premier league starts
|
71
|
-
# until (including) 1991-92} season
|
72
|
-
|
73
|
-
[1991-92]
|
74
|
-
1 => division1, English Division 1
|
75
|
-
2 => division2, English Division 2
|
76
|
-
3 => division3, English Division 3
|
77
|
-
3a => division3n, English Division 3 (North)
|
78
|
-
3b => division3s, English Division 3 (South)
|
79
|
-
4 => division4, English Division 4 ## check if real?
|
80
|
-
TXT
|
81
|
-
|
82
|
-
|
83
|
-
assert_equal 'premierleague', hash['*']['1']
|
84
|
-
assert_equal 'championship', hash['*']['2']
|
85
|
-
assert_equal 'league1', hash['*']['3']
|
86
|
-
|
87
|
-
assert_equal 'division1', hash['1991-92']['1']
|
88
|
-
assert_equal 'division2', hash['1991-92']['2']
|
89
|
-
end # method test_parse_leagues_txt
|
90
46
|
end # class TestLeagueUtils
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_team_reader.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestTeamReader < MiniTest::Test
|
11
|
+
|
12
|
+
def test_parse_at
|
13
|
+
recs = SportDb::Import::TeamReader.parse( <<TXT )
|
14
|
+
##########################
|
15
|
+
# Austria (AUT), at
|
16
|
+
|
17
|
+
FK Austria Wien, Wien
|
18
|
+
| Austria Vienna | Austria Wien
|
19
|
+
SK Rapid Wien, Wien
|
20
|
+
| Rapid Vienna | Rapid Wien
|
21
|
+
Wiener Sport-Club, Wien
|
22
|
+
TXT
|
23
|
+
|
24
|
+
pp recs
|
25
|
+
|
26
|
+
assert_equal 3, recs.size
|
27
|
+
assert_equal 'FK Austria Wien', recs[0].name
|
28
|
+
assert_equal 'Wien', recs[0].city
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_parse_us
|
32
|
+
recs = SportDb::Import::TeamReader.parse( <<TXT )
|
33
|
+
######################################################
|
34
|
+
# Major League Soccer (MLS) teams
|
35
|
+
|
36
|
+
Atlanta United FC, 2017, Atlanta › Georgia
|
37
|
+
| Atlanta United
|
38
|
+
Chicago Fire, 1998, Bridgeview › Illinois
|
39
|
+
FC Dallas, 1996, Frisco › Texas ## note: FC Dallas named >Dallas Burn< from 1996-2004
|
40
|
+
|
41
|
+
##################################
|
42
|
+
# Defunct / Historic
|
43
|
+
Miami Fusion (1998-2001), Fort Lauderdale › Florida
|
44
|
+
CD Chivas USA (2005-2014), Carson › California
|
45
|
+
| Chivas USA
|
46
|
+
TXT
|
47
|
+
|
48
|
+
pp recs
|
49
|
+
|
50
|
+
assert_equal 5, recs.size
|
51
|
+
assert_equal 'Atlanta United FC', recs[0].name
|
52
|
+
assert_equal 2017, recs[0].year
|
53
|
+
assert_equal 'Atlanta › Georgia', recs[0].city
|
54
|
+
end
|
55
|
+
|
56
|
+
end # class TestTeamReader
|