sportdb-formats 1.1.6 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +2 -0
- data/Manifest.txt +4 -25
- data/Rakefile +1 -1
- data/lib/sportdb/formats/country/country_reader.rb +142 -142
- data/lib/sportdb/formats/datafile.rb +59 -59
- data/lib/sportdb/formats/event/event_reader.rb +184 -183
- data/lib/sportdb/formats/goals.rb +53 -9
- data/lib/sportdb/formats/ground/ground_reader.rb +289 -0
- data/lib/sportdb/formats/league/league_reader.rb +152 -168
- data/lib/sportdb/formats/lines_reader.rb +47 -0
- data/lib/sportdb/formats/match/match_parser.rb +130 -13
- data/lib/sportdb/formats/match/match_parser_auto_conf.rb +270 -202
- data/lib/sportdb/formats/outline_reader.rb +0 -1
- data/lib/sportdb/formats/package.rb +394 -374
- data/lib/sportdb/formats/search/sport.rb +357 -0
- data/lib/sportdb/formats/search/world.rb +139 -0
- data/lib/sportdb/formats/team/club_index_history.rb +134 -134
- data/lib/sportdb/formats/team/club_reader.rb +318 -350
- data/lib/sportdb/formats/team/club_reader_history.rb +203 -203
- data/lib/sportdb/formats/team/wiki_reader.rb +108 -108
- data/lib/sportdb/formats/version.rb +4 -7
- data/lib/sportdb/formats.rb +60 -27
- metadata +13 -35
- data/lib/sportdb/formats/country/country_index.rb +0 -192
- data/lib/sportdb/formats/event/event_index.rb +0 -141
- data/lib/sportdb/formats/league/league_index.rb +0 -178
- data/lib/sportdb/formats/team/club_index.rb +0 -338
- data/lib/sportdb/formats/team/national_team_index.rb +0 -114
- data/lib/sportdb/formats/team/team_index.rb +0 -43
- data/test/helper.rb +0 -132
- data/test/test_club_index.rb +0 -183
- data/test/test_club_index_history.rb +0 -107
- data/test/test_club_reader.rb +0 -201
- data/test/test_club_reader_history.rb +0 -212
- data/test/test_club_reader_props.rb +0 -54
- data/test/test_country_index.rb +0 -63
- data/test/test_country_reader.rb +0 -89
- data/test/test_datafile.rb +0 -30
- data/test/test_datafile_package.rb +0 -46
- data/test/test_goals.rb +0 -113
- data/test/test_league_index.rb +0 -157
- data/test/test_league_outline_reader.rb +0 -55
- data/test/test_league_reader.rb +0 -72
- data/test/test_outline_reader.rb +0 -31
- data/test/test_package.rb +0 -78
- data/test/test_package_match.rb +0 -102
- data/test/test_regex.rb +0 -67
- data/test/test_wiki_reader.rb +0 -77
@@ -1,374 +1,394 @@
|
|
1
|
-
|
2
|
-
module SportDb
|
3
|
-
class Package
|
4
|
-
|
5
|
-
## todo/fix: make all regexes case-insensitive with /i option - why? why not?
|
6
|
-
## e.g. .TXT and .txt
|
7
|
-
## yes!! use /i option!!!!!
|
8
|
-
|
9
|
-
CONF_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
10
|
-
\.conf\.txt$
|
11
|
-
}x
|
12
|
-
|
13
|
-
## leagues.txt or leagues_en.txt
|
14
|
-
## remove support for en.leagues.txt - why? why not?
|
15
|
-
LEAGUES_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
16
|
-
(?: [a-z]{1,4}\. )? # optional country code/key e.g. eng.leagues.txt
|
17
|
-
leagues
|
18
|
-
(?:_[a-z0-9_-]+)?
|
19
|
-
\.txt$
|
20
|
-
}x
|
21
|
-
|
22
|
-
## seasons.txt or seasons_en.txt
|
23
|
-
## remove support for br.seasons.txt - why? why not?
|
24
|
-
SEASONS_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
25
|
-
(?: [a-z]{1,4}\. )? # optional country code/key e.g. eng.seasons.txt
|
26
|
-
seasons
|
27
|
-
(?:_[a-z0-9_-]+)?
|
28
|
-
\.txt$
|
29
|
-
}x
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
(?: [a-z]{1,4}\. )? # optional country code/key e.g. eng.clubs.txt
|
36
|
-
|
37
|
-
(?:_[a-z0-9_-]+)?
|
38
|
-
\.txt$
|
39
|
-
}x
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
}x
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
}x
|
64
|
-
|
65
|
-
##
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
## move
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
def self.
|
143
|
-
|
144
|
-
def self.
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
alias_method :
|
174
|
-
|
175
|
-
|
176
|
-
alias_method :
|
177
|
-
|
178
|
-
|
179
|
-
alias_method :
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
def
|
217
|
-
@include
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
if
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
def
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
end
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
def
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
##
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
##
|
316
|
-
##
|
317
|
-
##
|
318
|
-
|
319
|
-
##
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
##
|
331
|
-
|
332
|
-
##
|
333
|
-
##
|
334
|
-
##
|
335
|
-
##
|
336
|
-
##
|
337
|
-
##
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
##
|
354
|
-
##
|
355
|
-
##
|
356
|
-
|
357
|
-
##
|
358
|
-
|
359
|
-
|
360
|
-
h
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
1
|
+
|
2
|
+
module SportDb
|
3
|
+
class Package
|
4
|
+
|
5
|
+
## todo/fix: make all regexes case-insensitive with /i option - why? why not?
|
6
|
+
## e.g. .TXT and .txt
|
7
|
+
## yes!! use /i option!!!!!
|
8
|
+
|
9
|
+
CONF_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
10
|
+
\.conf\.txt$
|
11
|
+
}x
|
12
|
+
|
13
|
+
## leagues.txt or leagues_en.txt
|
14
|
+
## remove support for en.leagues.txt - why? why not?
|
15
|
+
LEAGUES_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
16
|
+
(?: [a-z]{1,4}\. )? # optional country code/key e.g. eng.leagues.txt
|
17
|
+
leagues
|
18
|
+
(?:_[a-z0-9_-]+)?
|
19
|
+
\.txt$
|
20
|
+
}x
|
21
|
+
|
22
|
+
## seasons.txt or seasons_en.txt
|
23
|
+
## remove support for br.seasons.txt - why? why not?
|
24
|
+
SEASONS_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
25
|
+
(?: [a-z]{1,4}\. )? # optional country code/key e.g. eng.seasons.txt
|
26
|
+
seasons
|
27
|
+
(?:_[a-z0-9_-]+)?
|
28
|
+
\.txt$
|
29
|
+
}x
|
30
|
+
|
31
|
+
|
32
|
+
####
|
33
|
+
# de.stadiums.txt or stadiums.txt or stadiums_de.txt
|
34
|
+
GROUNDS_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
35
|
+
(?: [a-z]{1,4}\. )? # optional country code/key e.g. eng.clubs.txt
|
36
|
+
stadiums
|
37
|
+
(?:_[a-z0-9_-]+)?
|
38
|
+
\.txt$
|
39
|
+
}x
|
40
|
+
|
41
|
+
PLAYERS_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
42
|
+
(?: [a-z]{1,4}\. )? # optional country code/key e.g. eng.clubs.txt
|
43
|
+
players
|
44
|
+
(?:_[a-z0-9_-]+)?
|
45
|
+
\.txt$
|
46
|
+
}x
|
47
|
+
|
48
|
+
|
49
|
+
## clubs.txt or clubs_en.txt
|
50
|
+
## remove support for en.clubs.txt - why? why not?
|
51
|
+
CLUBS_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
52
|
+
(?: [a-z]{1,4}\. )? # optional country code/key e.g. eng.clubs.txt
|
53
|
+
clubs
|
54
|
+
(?:_[a-z0-9_-]+)?
|
55
|
+
\.txt$
|
56
|
+
}x
|
57
|
+
|
58
|
+
CLUBS_WIKI_RE = %r{ (?:^|/) # beginning (^) or beginning of path (/)
|
59
|
+
(?:[a-z]{1,4}\.)? # optional country code/key e.g. eng.clubs.wiki.txt
|
60
|
+
clubs
|
61
|
+
(?:_[a-z0-9_-]+)?
|
62
|
+
\.wiki\.txt$
|
63
|
+
}x
|
64
|
+
|
65
|
+
## todo/fix: rename to CLUBS too e.g. CLUBS_PROPS to reflect filename - why? why not?
|
66
|
+
CLUBS_PROPS_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
67
|
+
(?: [a-z]{1,4}\. )? # optional country code/key e.g. eng.clubs.props.txt
|
68
|
+
clubs
|
69
|
+
(?:_[a-z0-9_-]+)?
|
70
|
+
\.props\.txt$
|
71
|
+
}x
|
72
|
+
CLUB_PROPS_RE = CLUBS_PROPS_RE ## add alias for now (fix later - why? why not?)
|
73
|
+
|
74
|
+
|
75
|
+
CLUBS_HISTORY_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
76
|
+
(?: [a-z]{1,4}\. )? # optional country code/key e.g. eng.clubs.history.txt
|
77
|
+
clubs
|
78
|
+
(?:_[a-z0-9_-]+)?
|
79
|
+
\.history\.txt$
|
80
|
+
}x
|
81
|
+
|
82
|
+
## teams.txt or teams_history.txt
|
83
|
+
TEAMS_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
84
|
+
teams
|
85
|
+
(?:_[a-z0-9_-]+)?
|
86
|
+
\.txt$
|
87
|
+
}x
|
88
|
+
|
89
|
+
|
90
|
+
### todo/fix: change SEASON_RE to SEASON_KEY_RE (avoid confusion w/ SEASONS_RE for datafile?) - why? why not? !!!!!!!
|
91
|
+
### season folder:
|
92
|
+
## e.g. /2019-20 or
|
93
|
+
## year-only e.g. /2019 or
|
94
|
+
## /2016--france
|
95
|
+
SEASON_RE = %r{ (?:
|
96
|
+
\d{4}-\d{2}
|
97
|
+
| \d{4}(--[a-z0-9_-]+)?
|
98
|
+
)
|
99
|
+
}x
|
100
|
+
SEASON = SEASON_RE.source ## "inline" helper for embedding in other regexes - keep? why? why not?
|
101
|
+
|
102
|
+
|
103
|
+
## note: if pattern includes directory add here
|
104
|
+
## (otherwise move to more "generic" datafile) - why? why not?
|
105
|
+
MATCH_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
106
|
+
#{SEASON}
|
107
|
+
/[a-z0-9_-]+\.txt$ ## txt e.g /1-premierleague.txt
|
108
|
+
}x
|
109
|
+
|
110
|
+
MATCH_CSV_RE = %r{ (?: ^|/ ) # beginning (^) or beginning of path (/)
|
111
|
+
#{SEASON}
|
112
|
+
/[a-z0-9_.-]+\.csv$ ## note: allow dot (.) too e.g /eng.1.csv
|
113
|
+
}x
|
114
|
+
|
115
|
+
### add "generic" pattern to find all csv datafiles
|
116
|
+
CSV_RE = %r{ (?: ^|/ )
|
117
|
+
[a-z0-9_.-]+\.csv$ ## note: allow dot (.) too e.g /eng.1.csv
|
118
|
+
}x
|
119
|
+
|
120
|
+
|
121
|
+
## move class-level "static" finders to DirPackage (do NOT work for now for zip packages) - why? why not?
|
122
|
+
|
123
|
+
def self.find( path, pattern )
|
124
|
+
datafiles = []
|
125
|
+
|
126
|
+
## check all txt files
|
127
|
+
## note: incl. files starting with dot (.)) as candidates (normally excluded with just *)
|
128
|
+
candidates = Dir.glob( "#{path}/**/{*,.*}.*" )
|
129
|
+
pp candidates
|
130
|
+
candidates.each do |candidate|
|
131
|
+
datafiles << candidate if pattern.match( candidate )
|
132
|
+
end
|
133
|
+
|
134
|
+
pp datafiles
|
135
|
+
datafiles
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
def self.find_teams( path, pattern: TEAMS_RE ) find( path, pattern ); end
|
140
|
+
def self.match_teams( path ) TEAMS_RE.match( path ); end
|
141
|
+
|
142
|
+
def self.find_clubs( path, pattern: CLUBS_RE ) find( path, pattern ); end
|
143
|
+
def self.find_clubs_wiki( path, pattern: CLUBS_WIKI_RE ) find( path, pattern ); end
|
144
|
+
def self.find_clubs_history( path, pattern: CLUBS_HISTORY_RE ) find( path, pattern ); end
|
145
|
+
|
146
|
+
def self.match_clubs( path ) CLUBS_RE.match( path ); end
|
147
|
+
def self.match_clubs_wiki( path ) CLUBS_WIKI_RE.match( path ); end
|
148
|
+
def self.match_clubs_history( path ) CLUBS_HISTORY_RE.match( path); end
|
149
|
+
def self.match_clubs_props( path, pattern: CLUBS_PROPS_RE ) pattern.match( path ); end
|
150
|
+
|
151
|
+
def self.find_leagues( path, pattern: LEAGUES_RE ) find( path, pattern ); end
|
152
|
+
def self.match_leagues( path ) LEAGUES_RE.match( path ); end
|
153
|
+
|
154
|
+
def self.find_seasons( path, pattern: SEASONS_RE ) find( path, pattern ); end
|
155
|
+
def self.match_seasons( path ) SEASONS_RE.match( path ); end
|
156
|
+
|
157
|
+
|
158
|
+
def self.find_conf( path, pattern: CONF_RE ) find( path, pattern ); end
|
159
|
+
def self.match_conf( path ) CONF_RE.match( path ); end
|
160
|
+
|
161
|
+
def self.find_match( path, format: 'txt' )
|
162
|
+
if format == 'csv'
|
163
|
+
find( path, MATCH_CSV_RE )
|
164
|
+
else ## otherwise always assume txt for now
|
165
|
+
find( path, MATCH_RE )
|
166
|
+
end
|
167
|
+
end
|
168
|
+
## add match_match and match_match_csv - why? why not?
|
169
|
+
|
170
|
+
|
171
|
+
class << self
|
172
|
+
alias_method :match_teams?, :match_teams
|
173
|
+
alias_method :teams?, :match_teams
|
174
|
+
|
175
|
+
alias_method :match_clubs?, :match_clubs
|
176
|
+
alias_method :clubs?, :match_clubs
|
177
|
+
|
178
|
+
alias_method :match_clubs_wiki?, :match_clubs_wiki
|
179
|
+
alias_method :clubs_wiki?, :match_clubs_wiki
|
180
|
+
|
181
|
+
alias_method :match_clubs_history?, :match_clubs_history
|
182
|
+
alias_method :clubs_history?, :match_clubs_history
|
183
|
+
|
184
|
+
alias_method :match_club_props, :match_clubs_props
|
185
|
+
alias_method :match_club_props?, :match_clubs_props
|
186
|
+
alias_method :club_props?, :match_clubs_props
|
187
|
+
alias_method :match_clubs_props?, :match_clubs_props
|
188
|
+
alias_method :clubs_props?, :match_clubs_props
|
189
|
+
|
190
|
+
alias_method :match_leagues?, :match_leagues
|
191
|
+
alias_method :leagues?, :match_leagues
|
192
|
+
|
193
|
+
alias_method :match_seasons?, :match_seasons
|
194
|
+
alias_method :seasons?, :match_seasons
|
195
|
+
|
196
|
+
alias_method :match_conf?, :match_conf
|
197
|
+
alias_method :conf?, :match_conf
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
## attr_reader :pack ## allow access to embedded ("low-level") delegate package (or hide!?) - why? why not?
|
202
|
+
attr_accessor :include, :exclude
|
203
|
+
|
204
|
+
## private helpers - like select returns true for keeping and false for skipping entry
|
205
|
+
def filter_clause( filter, entry )
|
206
|
+
if filter.is_a?( String )
|
207
|
+
entry.name.index( filter ) ? true : false
|
208
|
+
elsif filter.is_a?( Regexp )
|
209
|
+
filter.match( entry.name ) ? true : false
|
210
|
+
else ## assume
|
211
|
+
## todo/check: pass in entry (and NOT entry.name) - why? why not?
|
212
|
+
filter.call( entry )
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def filter( entry )
|
217
|
+
if @include
|
218
|
+
if filter_clause( @include, entry ) ## todo/check: is include a reserved keyword????
|
219
|
+
true ## todo/check: check for exclude here too - why? why not?
|
220
|
+
else
|
221
|
+
false
|
222
|
+
end
|
223
|
+
else
|
224
|
+
if @exclude && filter_clause( @exclude, entry )
|
225
|
+
false
|
226
|
+
else
|
227
|
+
true
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
def initialize( path_or_pack )
|
234
|
+
@include = nil
|
235
|
+
@exclude = nil
|
236
|
+
|
237
|
+
if path_or_pack.is_a?( Datafile::Package )
|
238
|
+
@pack = path_or_pack
|
239
|
+
else ## assume it's a (string) path
|
240
|
+
path = path_or_pack
|
241
|
+
if !File.exist?( path ) ## file or directory
|
242
|
+
puts "** !!! ERROR !!! file NOT found >#{path}<; cannot open package"
|
243
|
+
exit 1
|
244
|
+
end
|
245
|
+
|
246
|
+
if File.directory?( path )
|
247
|
+
@pack = Datafile::DirPackage.new( path ) ## delegate to "generic" package
|
248
|
+
elsif File.file?( path ) && File.extname( path ) == '.zip' # note: includes dot (.) eg .zip
|
249
|
+
@pack = Datafile::ZipPackage.new( path )
|
250
|
+
else
|
251
|
+
puts "** !!! ERROR !!! cannot open package - directory or file with .zip extension required"
|
252
|
+
exit 1
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
|
258
|
+
def each( pattern:, &blk )
|
259
|
+
@pack.each( pattern: pattern ) do |entry|
|
260
|
+
next unless filter( entry ) ## lets you use include/exclude filters
|
261
|
+
blk.call( entry )
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def each_conf( &blk ) each( pattern: CONF_RE, &blk ); end
|
266
|
+
def each_match( format: 'txt', &blk )
|
267
|
+
if format == 'csv'
|
268
|
+
each( pattern: MATCH_CSV_RE, &blk );
|
269
|
+
else
|
270
|
+
each( pattern: MATCH_RE, &blk );
|
271
|
+
end
|
272
|
+
end
|
273
|
+
def each_match_csv( &blk ) each( pattern: MATCH_CSV_RE, &blk ); end
|
274
|
+
def each_csv( &blk ) each( pattern: CSV_RE, &blk ); end
|
275
|
+
|
276
|
+
def each_club_props( &blk ) each( pattern: CLUB_PROPS_RE, &blk ); end
|
277
|
+
|
278
|
+
def each_leagues( &blk ) each( pattern: LEAGUES_RE, &blk ); end
|
279
|
+
def each_clubs( &blk ) each( pattern: CLUBS_RE, &blk ); end
|
280
|
+
def each_clubs_wiki( &blk ) each( pattern: CLUBS_WIKI_RE, &blk ); end
|
281
|
+
def each_clubs_history( &blk ) each( pattern: CLUBS_HISTORY_RE, &blk ); end
|
282
|
+
|
283
|
+
def each_seasons( &blk ) each( pattern: SEASONS_RE, &blk ); end
|
284
|
+
|
285
|
+
|
286
|
+
def each_grounds( &blk ) each( pattern: GROUNDS_RE, &blk ); end
|
287
|
+
def each_players( &blk ) each( pattern: PLAYERS_RE, &blk ); end
|
288
|
+
|
289
|
+
## return all match datafile entries
|
290
|
+
def match( format: 'txt' )
|
291
|
+
ary=[]; each_match( format: format ) {|entry| ary << entry }; ary;
|
292
|
+
end
|
293
|
+
alias_method :matches, :match
|
294
|
+
|
295
|
+
|
296
|
+
## todo/check: rename/change to match_by_dir - why? why not?
|
297
|
+
## still in use somewhere? move to attic? use match_by_season and delete by_season_dir? - why? why not?
|
298
|
+
def match_by_season_dir( format: 'txt' )
|
299
|
+
##
|
300
|
+
## [["1950s/1956-57",
|
301
|
+
## ["1950s/1956-57/1-division1.csv",
|
302
|
+
## "1950s/1956-57/2-division2.csv",
|
303
|
+
## "1950s/1956-57/3a-division3n.csv",
|
304
|
+
## "1950s/1956-57/3b-division3s.csv"]],
|
305
|
+
## ...]
|
306
|
+
|
307
|
+
h = {}
|
308
|
+
match( format: format ).each do |entry|
|
309
|
+
season_path = File.dirname( entry.name )
|
310
|
+
|
311
|
+
h[ season_path ] ||= []
|
312
|
+
h[ season_path ] << entry
|
313
|
+
end
|
314
|
+
|
315
|
+
## todo/fix: - add sort entries by name - why? why not?
|
316
|
+
## note: assume 1-,2- etc. gets us back sorted leagues
|
317
|
+
## - use sort. (will not sort by default?)
|
318
|
+
|
319
|
+
h.to_a ## return as array (or keep hash) - why? why not?
|
320
|
+
end # method match_by_season_dir
|
321
|
+
|
322
|
+
def match_by_season( format: 'txt', start: nil ) ## change/rename to by_season_key - why? why not?
|
323
|
+
|
324
|
+
## todo/note: in the future - season might be anything (e.g. part of a filename and NOT a directory) - why? why not?
|
325
|
+
|
326
|
+
## note: fold all sames seasons (even if in different directories)
|
327
|
+
## into same datafile list e.g.
|
328
|
+
## ["1957/58",
|
329
|
+
## ["1950s/1957-58/1-division1.csv",
|
330
|
+
## "1950s/1957-58/2-division2.csv",
|
331
|
+
## "1950s/1957-58/3a-division3n.csv",
|
332
|
+
## "1950s/1957-58/3b-division3s.csv"]],
|
333
|
+
## and
|
334
|
+
## ["1957/58",
|
335
|
+
## ["archives/1950s/1957-58/1-division1.csv",
|
336
|
+
## "archives/1950s/1957-58/2-division2.csv",
|
337
|
+
## "archives/1950s/1957-58/3a-division3n.csv",
|
338
|
+
## "archives/1950s/1957-58/3b-division3s.csv"]],
|
339
|
+
## should be together - why? why not?
|
340
|
+
|
341
|
+
####
|
342
|
+
# Example package:
|
343
|
+
# [["2012/13", ["2012-13/1-proleague.csv"]],
|
344
|
+
# ["2013/14", ["2013-14/1-proleague.csv"]],
|
345
|
+
# ["2014/15", ["2014-15/1-proleague.csv"]],
|
346
|
+
# ["2015/16", ["2015-16/1-proleague.csv"]],
|
347
|
+
# ["2016/17", ["2016-17/1-proleague.csv"]],
|
348
|
+
# ["2017/18", ["2017-18/1-proleague.csv"]]]
|
349
|
+
|
350
|
+
## todo/fix: (re)use a more generic filter instead of start for start of season only
|
351
|
+
|
352
|
+
## todo/fix: use a "generic" filter_season helper for easy reuse
|
353
|
+
## filter_season( clause, season_key )
|
354
|
+
## or better filter = SeasonFilter.new( clause )
|
355
|
+
## filter.skip? filter.include? ( season_sason_key )?
|
356
|
+
## fiteer.before?( season_key ) etc.
|
357
|
+
## find some good method names!!!!
|
358
|
+
season_start = start ? Season( start ) : nil
|
359
|
+
|
360
|
+
h = {}
|
361
|
+
match( format: format ).each do |entry|
|
362
|
+
## note: assume last directory in datafile path is the season part/key
|
363
|
+
season_q = File.basename( File.dirname( entry.name ))
|
364
|
+
season = Season.parse( season_q ) ## normalize season
|
365
|
+
|
366
|
+
## skip if start season before this season
|
367
|
+
next if season_start && season_start.start_year > season.start_year
|
368
|
+
|
369
|
+
h[ season.key ] ||= []
|
370
|
+
h[ season.key ] << entry
|
371
|
+
end
|
372
|
+
|
373
|
+
## todo/fix: - add sort entries by name - why? why not?
|
374
|
+
## note: assume 1-,2- etc. gets us back sorted leagues
|
375
|
+
## - use sort. (will not sort by default?)
|
376
|
+
|
377
|
+
## sort by season
|
378
|
+
## latest / newest first (and oldest last)
|
379
|
+
|
380
|
+
h.to_a.sort do |l,r| ## return as array (or keep hash) - why? why not?
|
381
|
+
r[0] <=> l[0]
|
382
|
+
end
|
383
|
+
end # method match_by_season
|
384
|
+
end # class Package
|
385
|
+
|
386
|
+
|
387
|
+
class DirPackage < Package
|
388
|
+
def initialize( path ) super( Datafile::DirPackage.new( path ) ); end
|
389
|
+
end
|
390
|
+
|
391
|
+
class ZipPackage < Package
|
392
|
+
def initialize( path ) super( Datafile::ZipPackage.new( path ) ); end
|
393
|
+
end
|
394
|
+
end # module SportDb
|