sportdb-config 0.3.2 → 0.3.3
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 -0
- data/lib/sportdb/config.rb +2 -0
- data/lib/sportdb/config/config.rb +0 -1
- data/lib/sportdb/config/countries.rb +200 -0
- data/lib/sportdb/config/team_reader.rb +108 -8
- data/lib/sportdb/config/version.rb +1 -1
- data/test/test_countries.rb +26 -0
- data/test/test_team_reader.rb +16 -2
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2a4445ef87f3b56b3ef17a685cdd0e1b2b576220
|
|
4
|
+
data.tar.gz: 508640a8a0a0e2519892d15d1ba7065e71738eea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 44cc3d79fcb8a16c34fe27c8ecdfb158a99ef308bd9a17901fd85c0849f1bddef3882c3878161738d1cb23f2a068d8e706bce5f28fb5b21bc2df94b427316447
|
|
7
|
+
data.tar.gz: d0e784ae220704714ebbd3187246bbd44b87c6dd55a01a6d79812d959fa2ad2772b788e4c5f910581fb3db7dfb82a72339d1cd0b18593579c932b46b71701f08
|
data/Manifest.txt
CHANGED
|
@@ -9,6 +9,7 @@ config/leagues/gr.txt
|
|
|
9
9
|
config/leagues/sco.txt
|
|
10
10
|
lib/sportdb/config.rb
|
|
11
11
|
lib/sportdb/config/config.rb
|
|
12
|
+
lib/sportdb/config/countries.rb
|
|
12
13
|
lib/sportdb/config/league.rb
|
|
13
14
|
lib/sportdb/config/league_reader.rb
|
|
14
15
|
lib/sportdb/config/league_utils.rb
|
|
@@ -17,6 +18,7 @@ lib/sportdb/config/team_reader.rb
|
|
|
17
18
|
lib/sportdb/config/version.rb
|
|
18
19
|
test/helper.rb
|
|
19
20
|
test/test_config.rb
|
|
21
|
+
test/test_countries.rb
|
|
20
22
|
test/test_league_reader.rb
|
|
21
23
|
test/test_league_utils.rb
|
|
22
24
|
test/test_season_utils.rb
|
data/lib/sportdb/config.rb
CHANGED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module SportDb
|
|
4
|
+
module Import
|
|
5
|
+
|
|
6
|
+
class Configuration
|
|
7
|
+
|
|
8
|
+
## built-in countries for (quick starter) auto-add
|
|
9
|
+
COUNTRIES = { ## rename to AUTO or BUILTIN_COUNTRIES or QUICK_COUNTRIES - why? why not?
|
|
10
|
+
## british isles
|
|
11
|
+
eng: ['England', 'ENG'], ## title/name, code
|
|
12
|
+
sco: ['Scotland', 'SCO'],
|
|
13
|
+
ie: ['Ireland', 'IRL'],
|
|
14
|
+
|
|
15
|
+
## central europe
|
|
16
|
+
at: ['Austria', 'AUT'],
|
|
17
|
+
de: ['Germany', 'GER'], ## use fifa code or iso? - using fifa for now
|
|
18
|
+
ch: ['Switzerland', 'SWZ'],
|
|
19
|
+
pl: ['Poland', 'POL'],
|
|
20
|
+
|
|
21
|
+
## western europe
|
|
22
|
+
fr: ['France', 'FRA'],
|
|
23
|
+
es: ['Spain', 'ESP'],
|
|
24
|
+
be: ['Belgium', '' ],
|
|
25
|
+
nl: ['Netherlands', '' ],
|
|
26
|
+
|
|
27
|
+
## northern europe / skandinavia
|
|
28
|
+
dk: ['Denmark', 'DNK'],
|
|
29
|
+
fi: ['Finland', 'FIN'],
|
|
30
|
+
no: ['Norway', 'NOR'],
|
|
31
|
+
se: ['Sweden', 'SWE'],
|
|
32
|
+
|
|
33
|
+
## eastern europe
|
|
34
|
+
ro: ['Romania', 'ROU'],
|
|
35
|
+
ru: ['Russia', 'RUS'],
|
|
36
|
+
|
|
37
|
+
## north america
|
|
38
|
+
us: ['United States', 'USA'],
|
|
39
|
+
mx: ['Mexico', 'MEX'],
|
|
40
|
+
|
|
41
|
+
## caribbean
|
|
42
|
+
ht: ['Haiti', ''],
|
|
43
|
+
pr: ['Puerto Rico', ''],
|
|
44
|
+
tt: ['Trinidad and Tobago', ''],
|
|
45
|
+
|
|
46
|
+
## central america
|
|
47
|
+
cr: ['Costa Rica', ''],
|
|
48
|
+
gt: ['Guatemala', ''],
|
|
49
|
+
hn: ['Honduras', ''],
|
|
50
|
+
ni: ['Nicaragua', ''],
|
|
51
|
+
pa: ['Panama', ''],
|
|
52
|
+
sv: ['El Salvador', ''],
|
|
53
|
+
|
|
54
|
+
## south america
|
|
55
|
+
ar: ['Argentina', 'ARG'],
|
|
56
|
+
br: ['Brazil', 'BRA'],
|
|
57
|
+
bo: ['Bolivia', ''],
|
|
58
|
+
cl: ['Chile', ''],
|
|
59
|
+
co: ['Colombia', ''],
|
|
60
|
+
ec: ['Ecuador', ''],
|
|
61
|
+
gy: ['Guyana', ''],
|
|
62
|
+
pe: ['Peru', ''],
|
|
63
|
+
py: ['Paraguay', ''],
|
|
64
|
+
uy: ['Uruguay', ''],
|
|
65
|
+
ve: ['Venezuela', ''],
|
|
66
|
+
|
|
67
|
+
## asia
|
|
68
|
+
cn: ['China', 'CHN'],
|
|
69
|
+
jp: ['Japan', 'JPN'],
|
|
70
|
+
kz: ['Kazakhstan', '' ],
|
|
71
|
+
kr: ['South Korea', '' ],
|
|
72
|
+
|
|
73
|
+
## africa
|
|
74
|
+
eg: ['Egypt', ''],
|
|
75
|
+
ma: ['Morocco', ''],
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
## add more countries - see/check datasets !!
|
|
79
|
+
=begin
|
|
80
|
+
[["eg", "../../../openfootball/clubs/africa/egypt/eg.clubs.txt"],
|
|
81
|
+
["ma", "../../../openfootball/clubs/africa/morocco/ma.clubs.txt"],
|
|
82
|
+
["cn", "../../../openfootball/clubs/asia/china/cn.clubs.txt"],
|
|
83
|
+
["jp", "../../../openfootball/clubs/asia/japan/jp.clubs.txt"],
|
|
84
|
+
["kz", "../../../openfootball/clubs/asia/kazakhstan/kz.clubs.txt"],
|
|
85
|
+
["kr", "../../../openfootball/clubs/asia/south-korea/kr.clubs.txt"],
|
|
86
|
+
["ht", "../../../openfootball/clubs/caribbean/haiti/ht.clubs.txt"],
|
|
87
|
+
["pr", "../../../openfootball/clubs/caribbean/puerto-rico/pr.clubs.txt"],
|
|
88
|
+
["tt",
|
|
89
|
+
"../../../openfootball/clubs/caribbean/trinidad-n-tobago/tt.clubs.txt"],
|
|
90
|
+
["cr", "../../../openfootball/clubs/central-america/costa-rica/cr.clubs.txt"],
|
|
91
|
+
["gt", "../../../openfootball/clubs/central-america/guatemala/gt.clubs.txt"],
|
|
92
|
+
["hn", "../../../openfootball/clubs/central-america/hn-honduras/clubs.txt"],
|
|
93
|
+
["ni", "../../../openfootball/clubs/central-america/ni-nicaragua/clubs.txt"],
|
|
94
|
+
["pa", "../../../openfootball/clubs/central-america/pa-panama/clubs.txt"],
|
|
95
|
+
["sv",
|
|
96
|
+
"../../../openfootball/clubs/central-america/sv-el-salvador/clubs.txt"],
|
|
97
|
+
["ad", "../../../openfootball/clubs/europe/ad-andorra/clubs.txt"],
|
|
98
|
+
["al", "../../../openfootball/clubs/europe/al-albania/clubs.txt"],
|
|
99
|
+
["am", "../../../openfootball/clubs/europe/am-armenia/clubs.txt"],
|
|
100
|
+
["at", "../../../openfootball/clubs/europe/at-austria/clubs.txt"],
|
|
101
|
+
["az", "../../../openfootball/clubs/europe/az-azerbaijan/clubs.txt"],
|
|
102
|
+
["ba",
|
|
103
|
+
"../../../openfootball/clubs/europe/ba-bosnia-n-herzegovina/clubs.txt"],
|
|
104
|
+
["be", "../../../openfootball/clubs/europe/be-belgium/clubs.txt"],
|
|
105
|
+
["bg", "../../../openfootball/clubs/europe/bg-bulgaria/clubs.txt"],
|
|
106
|
+
["by", "../../../openfootball/clubs/europe/by-belarus/clubs.txt"],
|
|
107
|
+
["ch",
|
|
108
|
+
"../../../openfootball/clubs/europe/ch-confoederatio-helvetica/clubs.txt"],
|
|
109
|
+
["cy", "../../../openfootball/clubs/europe/cy-cyprus/clubs.txt"],
|
|
110
|
+
["cz", "../../../openfootball/clubs/europe/cz-czech-republic/clubs.txt"],
|
|
111
|
+
["de", "../../../openfootball/clubs/europe/de-deutschland/clubs.txt"],
|
|
112
|
+
["dk", "../../../openfootball/clubs/europe/dk-denmark/clubs.txt"],
|
|
113
|
+
["ee", "../../../openfootball/clubs/europe/ee-estonia/clubs.txt"],
|
|
114
|
+
["eng", "../../../openfootball/clubs/europe/eng-england/clubs.txt"],
|
|
115
|
+
["es", "../../../openfootball/clubs/europe/es-espana/clubs.txt"],
|
|
116
|
+
["fi", "../../../openfootball/clubs/europe/fi-finland/clubs.txt"],
|
|
117
|
+
["fo", "../../../openfootball/clubs/europe/fo-faroe-islands/clubs.txt"],
|
|
118
|
+
["fr", "../../../openfootball/clubs/europe/fr-france/clubs.txt"],
|
|
119
|
+
["ge", "../../../openfootball/clubs/europe/ge-georgia/clubs.txt"],
|
|
120
|
+
["gi", "../../../openfootball/clubs/europe/gi-gibraltar/clubs.txt"],
|
|
121
|
+
["gr", "../../../openfootball/clubs/europe/gr-greece/clubs.txt"],
|
|
122
|
+
["hr", "../../../openfootball/clubs/europe/hr-croatia/clubs.txt"],
|
|
123
|
+
["hu", "../../../openfootball/clubs/europe/hu-hungary/clubs.txt"],
|
|
124
|
+
["ie", "../../../openfootball/clubs/europe/ie-ireland/clubs.txt"],
|
|
125
|
+
["is", "../../../openfootball/clubs/europe/is-iceland/clubs.txt"],
|
|
126
|
+
["it", "../../../openfootball/clubs/europe/it-italy/clubs.txt"],
|
|
127
|
+
["li", "../../../openfootball/clubs/europe/li-liechtenstein/clubs.txt"],
|
|
128
|
+
["lt", "../../../openfootball/clubs/europe/lt-lithuania/clubs.txt"],
|
|
129
|
+
["lu", "../../../openfootball/clubs/europe/lu-luxembourg/clubs.txt"],
|
|
130
|
+
["lv", "../../../openfootball/clubs/europe/lv-latvija/clubs.txt"],
|
|
131
|
+
["mc", "../../../openfootball/clubs/europe/mc-monaco/clubs.txt"],
|
|
132
|
+
["md", "../../../openfootball/clubs/europe/md-moldova/clubs.txt"],
|
|
133
|
+
["me", "../../../openfootball/clubs/europe/me-montenegro/clubs.txt"],
|
|
134
|
+
["mk", "../../../openfootball/clubs/europe/mk-macedonia/clubs.txt"],
|
|
135
|
+
["mt", "../../../openfootball/clubs/europe/mt-malta/clubs.txt"],
|
|
136
|
+
["nir", "../../../openfootball/clubs/europe/nir-northern-ireland/clubs.txt"],
|
|
137
|
+
["nl", "../../../openfootball/clubs/europe/nl-netherlands/clubs.txt"],
|
|
138
|
+
["no", "../../../openfootball/clubs/europe/no-norway/clubs.txt"],
|
|
139
|
+
["pl", "../../../openfootball/clubs/europe/pl-poland/clubs.txt"],
|
|
140
|
+
["pt", "../../../openfootball/clubs/europe/pt-portugal/clubs.txt"],
|
|
141
|
+
["ro", "../../../openfootball/clubs/europe/ro-romania/clubs.txt"],
|
|
142
|
+
["rs", "../../../openfootball/clubs/europe/rs-serbia/clubs.txt"],
|
|
143
|
+
["ru", "../../../openfootball/clubs/europe/ru-russia/clubs.txt"],
|
|
144
|
+
["sco", "../../../openfootball/clubs/europe/sco-scotland/clubs.txt"],
|
|
145
|
+
["se", "../../../openfootball/clubs/europe/se-sweden/clubs.txt"],
|
|
146
|
+
["si", "../../../openfootball/clubs/europe/si-slovenia/clubs.txt"],
|
|
147
|
+
["sk", "../../../openfootball/clubs/europe/sk-slovakia/clubs.txt"],
|
|
148
|
+
["sm", "../../../openfootball/clubs/europe/sm-san-marino/clubs.txt"],
|
|
149
|
+
["tr", "../../../openfootball/clubs/europe/tr-turkey/clubs.txt"],
|
|
150
|
+
["ua", "../../../openfootball/clubs/europe/ua-ukraine/clubs.txt"],
|
|
151
|
+
["wal", "../../../openfootball/clubs/europe/wal-wales/clubs.txt"],
|
|
152
|
+
["il", "../../../openfootball/clubs/middle-east/il-israel/clubs.txt"],
|
|
153
|
+
["ca", "../../../openfootball/clubs/north-america/ca-canada/clubs.txt"],
|
|
154
|
+
["mx", "../../../openfootball/clubs/north-america/mx-mexico/clubs.txt"],
|
|
155
|
+
["us",
|
|
156
|
+
"../../../openfootball/clubs/north-america/us-united-states/clubs.txt"],
|
|
157
|
+
["au", "../../../openfootball/clubs/pacific/australia/au.clubs.txt"],
|
|
158
|
+
["nz", "../../../openfootball/clubs/pacific/new-zealand/nz.clubs.txt"],
|
|
159
|
+
["ar", "../../../openfootball/clubs/south-america/argentina/ar.clubs.txt"],
|
|
160
|
+
["bo", "../../../openfootball/clubs/south-america/bolivia/bo.clubs.txt"],
|
|
161
|
+
["br", "../../../openfootball/clubs/south-america/brazil/br.clubs.txt"],
|
|
162
|
+
["cl", "../../../openfootball/clubs/south-america/chile/cl.clubs.txt"],
|
|
163
|
+
["co", "../../../openfootball/clubs/south-america/co-colombia/clubs.txt"],
|
|
164
|
+
["ec", "../../../openfootball/clubs/south-america/ec-ecuador/clubs.txt"],
|
|
165
|
+
["gy", "../../../openfootball/clubs/south-america/gy-guyana/clubs.txt"],
|
|
166
|
+
["pe", "../../../openfootball/clubs/south-america/pe-peru/clubs.txt"],
|
|
167
|
+
["py", "../../../openfootball/clubs/south-america/py-paraguay/clubs.txt"],
|
|
168
|
+
["uy", "../../../openfootball/clubs/south-america/uy-uruguay/clubs.txt"],
|
|
169
|
+
["ve", "../../../openfootball/clubs/south-america/ve-venezuela/clubs.txt"]]
|
|
170
|
+
=end
|
|
171
|
+
|
|
172
|
+
##
|
|
173
|
+
# note: use our own (internal) country struct for now - why? why not?
|
|
174
|
+
# - check that shape/structure/fields/attributes match
|
|
175
|
+
# the Country struct in sportdb-text (in SportDb::Struct::Country)
|
|
176
|
+
## and the ActiveRecord model !!!!
|
|
177
|
+
class Country
|
|
178
|
+
## note: is read-only/immutable for now - why? why not?
|
|
179
|
+
## add cities (array/list) - why? why not?
|
|
180
|
+
attr_reader :key, :name, :code
|
|
181
|
+
def initialize( key, name, code )
|
|
182
|
+
@key, @name, @code = key, name, code
|
|
183
|
+
end
|
|
184
|
+
end # class Country
|
|
185
|
+
|
|
186
|
+
## todo/check: rename to country_mappings - why? why not?
|
|
187
|
+
## or countries_by_code or countries_by_key
|
|
188
|
+
def countries
|
|
189
|
+
## note: convertcountry data to "proper" struct
|
|
190
|
+
@countries ||= COUNTRIES.each.reduce({}) do |h,(key,value)|
|
|
191
|
+
## note: convert key (e.g. :eng to string e.g. 'eng')
|
|
192
|
+
h[key] = Country.new( key.to_s, value[0], value[1] )
|
|
193
|
+
h
|
|
194
|
+
end
|
|
195
|
+
@countries
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
end # class Configuration
|
|
199
|
+
end # module Import
|
|
200
|
+
end # module SportDb
|
|
@@ -16,15 +16,14 @@ class Team
|
|
|
16
16
|
attr_accessor :name, :alt_names, :year, :ground, :city
|
|
17
17
|
|
|
18
18
|
## more attribs - todo/fix - also add "upstream" to struct & model!!!!!
|
|
19
|
-
attr_accessor :district, :geos, :year_end
|
|
19
|
+
attr_accessor :district, :geos, :year_end, :country
|
|
20
20
|
|
|
21
|
-
def historic?() @year_end
|
|
21
|
+
def historic?() @year_end ? true : false; end
|
|
22
22
|
alias_method :past?, :historic?
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
def initialize
|
|
26
26
|
@alt_names = []
|
|
27
|
-
@year_end = nil
|
|
28
27
|
end
|
|
29
28
|
|
|
30
29
|
|
|
@@ -42,6 +41,7 @@ end
|
|
|
42
41
|
def self.parse( txt )
|
|
43
42
|
recs = []
|
|
44
43
|
last_rec = nil
|
|
44
|
+
headings = [] ## headings stack
|
|
45
45
|
|
|
46
46
|
txt.each_line do |line|
|
|
47
47
|
line = line.strip
|
|
@@ -69,7 +69,64 @@ def self.parse( txt )
|
|
|
69
69
|
heading = $2.strip
|
|
70
70
|
|
|
71
71
|
puts "heading #{heading_level} >#{heading}<"
|
|
72
|
-
|
|
72
|
+
|
|
73
|
+
## 1) first pop headings if present
|
|
74
|
+
while headings.size+1 > heading_level
|
|
75
|
+
headings.pop
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
## 2) add missing (hierarchy) level if
|
|
79
|
+
while headings.size+1 < heading_level
|
|
80
|
+
## todo/fix: issue warning about "skipping" hierarchy level
|
|
81
|
+
puts "!!! warn [team reader] - skipping hierarchy level in headings "
|
|
82
|
+
headings.push( nil )
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
if heading =~ /^\?+$/ ## note: use ? or ?? or ?? to reset level to nil
|
|
86
|
+
## keep level empty
|
|
87
|
+
else
|
|
88
|
+
|
|
89
|
+
## quick hack: if level is 1 assume country for now
|
|
90
|
+
## and extract country code e.g.
|
|
91
|
+
## Austria (at) => at
|
|
92
|
+
if heading_level == 1
|
|
93
|
+
if heading =~ /\(([a-z]{2,3})\)/
|
|
94
|
+
country_code = $1
|
|
95
|
+
|
|
96
|
+
## check country code - MUST exist for now!!!!
|
|
97
|
+
country = SportDb::Import.config.countries[ country_code.to_sym ]
|
|
98
|
+
if country.nil?
|
|
99
|
+
puts "!!! error [team reader] - unknown country with code >#{country_code}< - sorry - add country to config to fix"
|
|
100
|
+
exit 1
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
headings.push( country_code )
|
|
104
|
+
else
|
|
105
|
+
puts "!!! error - heading level 1 - missing country code - >#{heading}<"
|
|
106
|
+
exit 1
|
|
107
|
+
end
|
|
108
|
+
else
|
|
109
|
+
## quick hack:
|
|
110
|
+
## remove known fill/dummy words incl:
|
|
111
|
+
## Provincia San Juan => San Juan (see argentina, for example)
|
|
112
|
+
##
|
|
113
|
+
## use geo tree long term with alternative names - why? why not?
|
|
114
|
+
words = ['Provincia']
|
|
115
|
+
words.each { |word| heading = heading.gsub( word, '' ) }
|
|
116
|
+
heading = heading.strip
|
|
117
|
+
|
|
118
|
+
headings.push( heading )
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
## assert that hierarchy level is ok
|
|
122
|
+
if headings.size != heading_level
|
|
123
|
+
puts "!!! error - headings hierarchy/stack out of order - #{heading.size}<=>#{heading_level}"
|
|
124
|
+
exit 1
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
pp headings
|
|
129
|
+
|
|
73
130
|
elsif line.start_with?( '|' )
|
|
74
131
|
## assume continuation with line of alternative names
|
|
75
132
|
## note: skip leading pipe
|
|
@@ -152,10 +209,8 @@ def self.parse( txt )
|
|
|
152
209
|
else
|
|
153
210
|
## assume city / geo tree
|
|
154
211
|
## split into geo tree
|
|
155
|
-
geos =
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
city = geos[0]
|
|
212
|
+
geos = split_geo( value )
|
|
213
|
+
city = geos[0]
|
|
159
214
|
## check for "embedded" district e.g. London (Fulham) or Hamburg (St. Pauli) etc.
|
|
160
215
|
if city =~ /\((.+?)\)/ ## note: use non-greedy (?) match
|
|
161
216
|
rec.district = $1.strip
|
|
@@ -168,6 +223,37 @@ def self.parse( txt )
|
|
|
168
223
|
rec.geos = geos[1..-1]
|
|
169
224
|
end
|
|
170
225
|
end
|
|
226
|
+
end ## while values
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
###############
|
|
230
|
+
## use headings text for geo tree
|
|
231
|
+
|
|
232
|
+
## 1) add country if present
|
|
233
|
+
if headings.size > 0 && headings[0]
|
|
234
|
+
country = SportDb::Import.config.countries[ headings[0].to_sym ]
|
|
235
|
+
rec.country = country
|
|
236
|
+
else
|
|
237
|
+
## make it an error - why? why not?
|
|
238
|
+
puts "!!! warn - country missing in headings hierarchy"
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
## 2) check geo tree with headings hierarchy
|
|
242
|
+
if headings.size > 1 && headings[1]
|
|
243
|
+
geos = split_geo( headings[1] )
|
|
244
|
+
if rec.geos
|
|
245
|
+
if rec.geos[0] != geos[0]
|
|
246
|
+
puts "!!! error - geo tree - headings mismatch >#{rec.geos[0]}< <=> >#{geos[0]}<"
|
|
247
|
+
exit 1
|
|
248
|
+
end
|
|
249
|
+
if rec.geos[1] && rec.geos[1] != geos[1] ## check optional 2nd level too
|
|
250
|
+
puts "!!! error - geo tree - headings mismatch >#{rec.geos[1]}< <=> >#{geos[1]}<"
|
|
251
|
+
exit 1
|
|
252
|
+
end
|
|
253
|
+
else
|
|
254
|
+
## add missing region (state/province) from headings hierarchy
|
|
255
|
+
rec.geos = geos
|
|
256
|
+
end
|
|
171
257
|
end
|
|
172
258
|
|
|
173
259
|
last_rec = rec
|
|
@@ -191,6 +277,20 @@ def self.parse( txt )
|
|
|
191
277
|
end # each_line
|
|
192
278
|
recs
|
|
193
279
|
end # method read
|
|
280
|
+
|
|
281
|
+
### helpers
|
|
282
|
+
def self.split_geo( str )
|
|
283
|
+
## assume city / geo tree
|
|
284
|
+
## strip and squish (white)spaces
|
|
285
|
+
# e.g. León › Guanajuato => León › Guanajuato
|
|
286
|
+
str = str.strip.gsub( /[ \t]+/, ' ' )
|
|
287
|
+
|
|
288
|
+
## split into geo tree
|
|
289
|
+
geos = str.split( /[<>‹›]/ ) ## note: allow > < or › ‹
|
|
290
|
+
geos = geos.map { |geo| geo.strip } ## remove all whitespaces
|
|
291
|
+
geos
|
|
292
|
+
end
|
|
293
|
+
|
|
194
294
|
end # class TeamReader
|
|
195
295
|
|
|
196
296
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
###
|
|
4
|
+
# to run use
|
|
5
|
+
# ruby -I ./lib -I ./test test/test_countries.rb
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
require 'helper'
|
|
9
|
+
|
|
10
|
+
class TestCountries < MiniTest::Test
|
|
11
|
+
|
|
12
|
+
def test_countries
|
|
13
|
+
pp SportDb::Import.config.countries
|
|
14
|
+
|
|
15
|
+
eng = SportDb::Import.config.countries[:eng]
|
|
16
|
+
assert_equal 'eng', eng.key
|
|
17
|
+
assert_equal 'England', eng.name
|
|
18
|
+
assert_equal 'ENG', eng.code
|
|
19
|
+
|
|
20
|
+
at = SportDb::Import.config.countries[:at]
|
|
21
|
+
assert_equal 'at', at.key
|
|
22
|
+
assert_equal 'Austria', at.name
|
|
23
|
+
assert_equal 'AUT', at.code
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end # class TestCountries
|
data/test/test_team_reader.rb
CHANGED
|
@@ -60,6 +60,7 @@ TXT
|
|
|
60
60
|
|
|
61
61
|
def test_parse_years
|
|
62
62
|
recs = SportDb::Import::TeamReader.parse( <<TXT )
|
|
63
|
+
= United States (us)
|
|
63
64
|
FC Dallas (1996-), Frisco › Texas
|
|
64
65
|
Miami Fusion (1998-2001), Fort Lauderdale › Florida
|
|
65
66
|
CD Chivas USA (-2014), Carson › California
|
|
@@ -84,12 +85,17 @@ TXT
|
|
|
84
85
|
|
|
85
86
|
def test_parse_geos
|
|
86
87
|
recs = SportDb::Import::TeamReader.parse( <<TXT )
|
|
88
|
+
= England (eng)
|
|
89
|
+
== Greater London
|
|
87
90
|
|
|
88
91
|
Fulham FC, 1879, @ Craven Cottage, London (Fulham) › Greater London
|
|
89
92
|
| Fulham | FC Fulham
|
|
90
93
|
Charlton Athletic FC, @ The Valley, London (Charlton) › Greater London
|
|
91
94
|
| Charlton | Charlton Athletic
|
|
92
95
|
|
|
96
|
+
= Deutschland (de)
|
|
97
|
+
== Hamburg
|
|
98
|
+
|
|
93
99
|
St. Pauli, Hamburg (St. Pauli)
|
|
94
100
|
TXT
|
|
95
101
|
|
|
@@ -99,13 +105,17 @@ TXT
|
|
|
99
105
|
assert_equal 'London', recs[0].city
|
|
100
106
|
assert_equal 'Fulham', recs[0].district
|
|
101
107
|
assert_equal ['Greater London'], recs[0].geos
|
|
108
|
+
assert_equal 'eng', recs[0].country
|
|
102
109
|
|
|
103
110
|
assert_equal 'London', recs[1].city
|
|
104
111
|
assert_equal 'Charlton', recs[1].district
|
|
105
112
|
assert_equal ['Greater London'], recs[1].geos
|
|
113
|
+
assert_equal 'eng', recs[1].country
|
|
106
114
|
|
|
107
115
|
assert_equal 'Hamburg', recs[2].city
|
|
108
116
|
assert_equal 'St. Pauli', recs[2].district
|
|
117
|
+
assert_equal ['Hamburg'], recs[2].geos
|
|
118
|
+
assert_equal 'de', recs[2].country
|
|
109
119
|
end
|
|
110
120
|
|
|
111
121
|
|
|
@@ -114,8 +124,8 @@ TXT
|
|
|
114
124
|
==============
|
|
115
125
|
====
|
|
116
126
|
===========
|
|
117
|
-
= Heading 1
|
|
118
|
-
= Heading 1 ==================
|
|
127
|
+
= Heading 1 - Austria (at)
|
|
128
|
+
= Heading 1 - Austria (at) ==================
|
|
119
129
|
== Heading 2
|
|
120
130
|
== Heading 2 =========
|
|
121
131
|
=== Heading 3
|
|
@@ -123,6 +133,10 @@ TXT
|
|
|
123
133
|
=== Heading 3 # with end-of-line comment
|
|
124
134
|
=== Heading 3 ## with end-of-line comment
|
|
125
135
|
=== Heading 3 ========= # with end-of-line comment
|
|
136
|
+
== Heading 2
|
|
137
|
+
==== Heading 4
|
|
138
|
+
= ?????
|
|
139
|
+
== ???
|
|
126
140
|
TXT
|
|
127
141
|
|
|
128
142
|
pp recs
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sportdb-config
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gerald Bauer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-07-
|
|
11
|
+
date: 2019-07-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rdoc
|
|
@@ -63,6 +63,7 @@ files:
|
|
|
63
63
|
- config/leagues/sco.txt
|
|
64
64
|
- lib/sportdb/config.rb
|
|
65
65
|
- lib/sportdb/config/config.rb
|
|
66
|
+
- lib/sportdb/config/countries.rb
|
|
66
67
|
- lib/sportdb/config/league.rb
|
|
67
68
|
- lib/sportdb/config/league_reader.rb
|
|
68
69
|
- lib/sportdb/config/league_utils.rb
|
|
@@ -71,6 +72,7 @@ files:
|
|
|
71
72
|
- lib/sportdb/config/version.rb
|
|
72
73
|
- test/helper.rb
|
|
73
74
|
- test/test_config.rb
|
|
75
|
+
- test/test_countries.rb
|
|
74
76
|
- test/test_league_reader.rb
|
|
75
77
|
- test/test_league_utils.rb
|
|
76
78
|
- test/test_season_utils.rb
|