sportdb-quick 0.5.1 → 0.5.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/CHANGELOG.md +1 -1
- data/Manifest.txt +3 -1
- data/lib/sportdb/quick/match_parser.rb +113 -44
- data/lib/sportdb/quick/outline.rb +96 -0
- data/lib/sportdb/quick/outline_reader.rb +98 -0
- data/lib/sportdb/quick/{quick_league_outline_reader.rb → quick_league_outline.rb} +54 -26
- data/lib/sportdb/quick/quick_match_reader.rb +10 -12
- data/lib/sportdb/quick/version.rb +1 -1
- data/lib/sportdb/quick.rb +9 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d63bcffa581bc99cdc5dfaa7d80dd7dd8925dac90da349c43c6fdc5069e2c78
|
4
|
+
data.tar.gz: 1914dd71b5c39a2bea1eb58eca6126d31446a001ec0534656b943a865dc4a99b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9ce783a2f8c21d49a6571b86310fe023578aa7604d39672b7b8a4468d708bbd0c9104522cf2632f38765043ef06707a2a39c33cb53146072ed17f86879b3ef7
|
7
|
+
data.tar.gz: 309f14ee3e37133d8d53d4c51f86e2ebecbe974a3489ce9571f840e9d6ab521956abc5adc6e4e6301e3267daccf3a61711bc0d4d13c129450044fdfa33ce15e3
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
@@ -4,6 +4,8 @@ README.md
|
|
4
4
|
Rakefile
|
5
5
|
lib/sportdb/quick.rb
|
6
6
|
lib/sportdb/quick/match_parser.rb
|
7
|
-
lib/sportdb/quick/
|
7
|
+
lib/sportdb/quick/outline.rb
|
8
|
+
lib/sportdb/quick/outline_reader.rb
|
9
|
+
lib/sportdb/quick/quick_league_outline.rb
|
8
10
|
lib/sportdb/quick/quick_match_reader.rb
|
9
11
|
lib/sportdb/quick/version.rb
|
@@ -32,22 +32,36 @@ class MatchParser ## simple match parser for team match schedules
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
##
|
38
|
-
|
35
|
+
def _prep_lines( lines ) ## todo/check: add alias preproc_lines or build_lines or prep_lines etc. - why? why not?
|
36
|
+
|
37
|
+
## todo/fix - rework and make simpler
|
38
|
+
## no need to double join array of string to txt etc.
|
39
|
+
|
40
|
+
txt = if lines.is_a?( Array )
|
41
|
+
## join together with newline
|
42
|
+
lines.reduce( String.new ) do |mem,line|
|
43
|
+
mem << line; mem << "\n"; mem
|
44
|
+
end
|
45
|
+
else ## assume single-all-in-one txt
|
46
|
+
lines
|
47
|
+
end
|
48
|
+
|
49
|
+
## preprocess automagically - why? why not?
|
50
|
+
## strip lines with comments and empty lines striped / removed
|
51
|
+
txt_new = String.new
|
39
52
|
txt.each_line do |line| ## preprocess
|
40
53
|
line = line.strip
|
41
54
|
next if line.empty? || line.start_with?('#') ### skip empty lines and comments
|
42
55
|
|
43
56
|
line = line.sub( /#.*/, '' ).strip ### cut-off end-of line comments too
|
44
|
-
|
57
|
+
|
58
|
+
txt_new << line
|
59
|
+
txt_new << "\n"
|
45
60
|
end
|
46
|
-
|
61
|
+
txt_new
|
47
62
|
end
|
48
63
|
|
49
64
|
|
50
|
-
|
51
65
|
#
|
52
66
|
# todo/fix: change start to start: too!!!
|
53
67
|
# might be optional in the future!! - why? why not?
|
@@ -58,10 +72,18 @@ class MatchParser ## simple match parser for team match schedules
|
|
58
72
|
## todo/check: change to text instead of array of lines - why? why not?
|
59
73
|
|
60
74
|
## note - wrap in enumerator/iterator a.k.a lines reader
|
61
|
-
@lines = lines.is_a?( String ) ?
|
62
|
-
|
75
|
+
## @lines = lines.is_a?( String ) ?
|
76
|
+
## _read_lines( lines ) : lines
|
63
77
|
|
78
|
+
@txt = _prep_lines( lines )
|
79
|
+
|
80
|
+
### todo/fix - FIX/FIX
|
81
|
+
## check start year from first date
|
82
|
+
## for now (auot-)update - @start with every date that incl. a year!!!
|
64
83
|
@start = start
|
84
|
+
@last_year = nil
|
85
|
+
|
86
|
+
|
65
87
|
@errors = []
|
66
88
|
end
|
67
89
|
|
@@ -90,17 +112,9 @@ class MatchParser ## simple match parser for team match schedules
|
|
90
112
|
@tree = []
|
91
113
|
|
92
114
|
|
93
|
-
## flatten lines
|
94
|
-
txt = []
|
95
|
-
@lines.each_with_index do |line,i|
|
96
|
-
txt << line
|
97
|
-
txt << "\n"
|
98
|
-
end
|
99
|
-
txt = txt.join
|
100
|
-
|
101
115
|
if debug?
|
102
116
|
puts "lines:"
|
103
|
-
pp txt
|
117
|
+
pp @txt
|
104
118
|
end
|
105
119
|
|
106
120
|
=begin
|
@@ -123,7 +137,7 @@ class MatchParser ## simple match parser for team match schedules
|
|
123
137
|
@tree << t
|
124
138
|
=end
|
125
139
|
|
126
|
-
parser = RaccMatchParser.new( txt ) ## use own parser instance (not shared) - why? why not?
|
140
|
+
parser = RaccMatchParser.new( @txt ) ## use own parser instance (not shared) - why? why not?
|
127
141
|
@tree = parser.parse
|
128
142
|
## pp @tree
|
129
143
|
|
@@ -143,6 +157,8 @@ class MatchParser ## simple match parser for team match schedules
|
|
143
157
|
on_group_def( node )
|
144
158
|
elsif node.is_a? RaccMatchParser::GroupHeader
|
145
159
|
on_group_header( node )
|
160
|
+
elsif node.is_a? RaccMatchParser::RoundOutline
|
161
|
+
on_round_outline( node )
|
146
162
|
elsif node.is_a? RaccMatchParser::RoundHeader
|
147
163
|
on_round_header( node )
|
148
164
|
elsif node.is_a? RaccMatchParser::DateHeader
|
@@ -151,6 +167,8 @@ class MatchParser ## simple match parser for team match schedules
|
|
151
167
|
on_match_line( node )
|
152
168
|
elsif node.is_a? RaccMatchParser::GoalLine
|
153
169
|
on_goal_line( node )
|
170
|
+
elsif node.is_a? RaccMatchParser::LineupLine
|
171
|
+
## skip lineup for now
|
154
172
|
else
|
155
173
|
## report error
|
156
174
|
msg = "!! WARN - unknown node (parse tree type) - #{node.class.name}"
|
@@ -159,7 +177,6 @@ class MatchParser ## simple match parser for team match schedules
|
|
159
177
|
|
160
178
|
log( msg )
|
161
179
|
log( node.pretty_inspect )
|
162
|
-
## exit 1
|
163
180
|
end
|
164
181
|
end # tree.each
|
165
182
|
|
@@ -226,23 +243,31 @@ class MatchParser ## simple match parser for team match schedules
|
|
226
243
|
pp start
|
227
244
|
end
|
228
245
|
|
246
|
+
|
229
247
|
if y.nil? ## try to calculate year
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
248
|
+
if @last_year ## use new formula
|
249
|
+
y = @last_year
|
250
|
+
else ## fallback to "old" formula - FIX/FIX remove later
|
251
|
+
puts "[deprecated] WARN - do NOT use old year (date) auto-complete; add year to first date"
|
252
|
+
y = if m > start.month ||
|
253
|
+
(m == start.month && d >= start.day)
|
254
|
+
# assume same year as start_at event (e.g. 2013 for 2013/14 season)
|
255
|
+
start.year
|
256
|
+
else
|
257
|
+
# assume year+1 as start_at event (e.g. 2014 for 2013/14 season)
|
258
|
+
start.year+1
|
259
|
+
end
|
260
|
+
end
|
261
|
+
else
|
262
|
+
### note - reset @start to new date
|
263
|
+
## use @last_year
|
264
|
+
@last_year = y
|
238
265
|
end
|
239
266
|
|
240
267
|
|
241
|
-
|
242
268
|
Date.new( y,m,d ) ## y,m,d
|
243
269
|
end
|
244
270
|
|
245
|
-
|
246
271
|
def on_round_def( node )
|
247
272
|
logger.debug "on round def: >#{node}<"
|
248
273
|
|
@@ -308,15 +333,51 @@ class MatchParser ## simple match parser for team match schedules
|
|
308
333
|
end
|
309
334
|
|
310
335
|
|
336
|
+
|
337
|
+
|
338
|
+
def on_round_outline( node )
|
339
|
+
logger.debug "on round outline: >#{node}<"
|
340
|
+
|
341
|
+
## always reset dates - why? why not?
|
342
|
+
## note - needs last_date for year
|
343
|
+
## track last_year with extra variable
|
344
|
+
|
345
|
+
name = node.outline
|
346
|
+
|
347
|
+
round = @rounds[ name ]
|
348
|
+
if round.nil? ## auto-add / create if missing
|
349
|
+
## todo/check: add num (was pos) if present - why? why not?
|
350
|
+
round = Import::Round.new( name: name )
|
351
|
+
@rounds[ name ] = round
|
352
|
+
end
|
353
|
+
|
354
|
+
## todo/check: if pos match (MUST always match for now)
|
355
|
+
@last_round = round
|
356
|
+
@last_group = nil # note: reset group to no group - why? why not?
|
357
|
+
|
358
|
+
## todo/fix/check
|
359
|
+
## make round a scope for date(time) - why? why not?
|
360
|
+
## reset date/time e.g. @last_date = nil !!!!
|
361
|
+
end
|
362
|
+
|
363
|
+
|
311
364
|
def on_round_header( node )
|
312
365
|
logger.debug "on round header: >#{node}<"
|
313
366
|
|
314
|
-
|
315
|
-
|
367
|
+
### note - auto-add names with - for now (use comma)
|
368
|
+
## why? why not?
|
369
|
+
### check - use ' - ' for separator - why? why not?
|
370
|
+
name = node.names.join( ', ' )
|
371
|
+
=begin
|
372
|
+
## note: was node.names[0] ## ignore more names for now
|
373
|
+
## fix later - fix more names!!!
|
374
|
+
=end
|
316
375
|
|
317
|
-
|
376
|
+
# name = name.sub( ROUND_EXTRA_WORDS_RE, '' )
|
318
377
|
# name = name.strip
|
319
378
|
|
379
|
+
|
380
|
+
|
320
381
|
round = @rounds[ name ]
|
321
382
|
if round.nil? ## auto-add / create if missing
|
322
383
|
## todo/check: add num (was pos) if present - why? why not?
|
@@ -566,18 +627,26 @@ class GoalStruct
|
|
566
627
|
time_str = time if date && time
|
567
628
|
|
568
629
|
|
569
|
-
ground
|
630
|
+
ground = nil
|
631
|
+
timezone = nil
|
632
|
+
if node.geo
|
633
|
+
ground = node.geo
|
634
|
+
## note: only add/check for timezone if geo (aka ground) is present - why? why not?
|
635
|
+
timezone = node.timezone if node.timezone
|
636
|
+
end
|
637
|
+
|
570
638
|
|
571
|
-
@matches << Import::Match.new( num:
|
572
|
-
date:
|
573
|
-
time:
|
574
|
-
team1:
|
575
|
-
team2:
|
576
|
-
score:
|
577
|
-
round:
|
578
|
-
group:
|
579
|
-
status:
|
580
|
-
ground:
|
639
|
+
@matches << Import::Match.new( num: num,
|
640
|
+
date: date_str,
|
641
|
+
time: time_str,
|
642
|
+
team1: team1, ## note: for now always use mapping value e.g. rec (NOT string e.g. team1.name)
|
643
|
+
team2: team2, ## note: for now always use mapping value e.g. rec (NOT string e.g. team2.name)
|
644
|
+
score: score,
|
645
|
+
round: round ? round.name : nil, ## note: for now always use string (assume unique canonical name for event)
|
646
|
+
group: @last_group ? @last_group.name : nil, ## note: for now always use string (assume unique canonical name for event)
|
647
|
+
status: status,
|
648
|
+
ground: ground,
|
649
|
+
timezone: timezone )
|
581
650
|
### todo: cache team lookups in hash?
|
582
651
|
end
|
583
652
|
end # class MatchParser
|
@@ -0,0 +1,96 @@
|
|
1
|
+
|
2
|
+
module SportDb
|
3
|
+
|
4
|
+
###
|
5
|
+
# add a simple Outline convenience class
|
6
|
+
# for processing OUtlines with OUtlineReader
|
7
|
+
# rename to simply Outline - why? why not?
|
8
|
+
# todo - add more processing options - why? why not?
|
9
|
+
|
10
|
+
class Outline
|
11
|
+
def self.read( path )
|
12
|
+
nodes = OutlineReader.read( path )
|
13
|
+
new( nodes )
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.parse( txt )
|
17
|
+
nodes = OutlineReader.parse( txt )
|
18
|
+
new( nodes )
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def initialize( nodes )
|
23
|
+
@nodes = nodes
|
24
|
+
end
|
25
|
+
|
26
|
+
def each_para( &blk )
|
27
|
+
## note: every (new) read call - resets errors list to empty
|
28
|
+
### @errors = []
|
29
|
+
|
30
|
+
## process nodes
|
31
|
+
h1 = nil
|
32
|
+
h2 = nil
|
33
|
+
orphans = 0 ## track paragraphs's with no heading
|
34
|
+
|
35
|
+
@nodes.each do |node|
|
36
|
+
type = node[0]
|
37
|
+
|
38
|
+
if type == :h1
|
39
|
+
h1 = node[1] ## get heading text
|
40
|
+
puts " = Heading 1 >#{node[1]}<"
|
41
|
+
elsif type == :h2
|
42
|
+
if h1.nil?
|
43
|
+
puts "!! WARN - no heading for subheading; skipping processing"
|
44
|
+
next
|
45
|
+
end
|
46
|
+
h2 = node[1] ## get heading text
|
47
|
+
puts " == Heading 2 >#{node[1]}<"
|
48
|
+
elsif type == :p
|
49
|
+
if h1.nil?
|
50
|
+
orphans += 1 ## only warn once
|
51
|
+
puts "!! WARN - no heading for #{orphans} text paragraph(s); skipping parse"
|
52
|
+
next
|
53
|
+
end
|
54
|
+
|
55
|
+
lines = node[1]
|
56
|
+
blk.call( lines )
|
57
|
+
else
|
58
|
+
pp node
|
59
|
+
raise ArgumentError, "unsupported (node) type >#{type}<"
|
60
|
+
end
|
61
|
+
end # each node
|
62
|
+
end # each_para
|
63
|
+
alias_method :each_paragraph, :each_para
|
64
|
+
|
65
|
+
|
66
|
+
## get all para(graphs) as text (not array of lines)
|
67
|
+
## make default - why? why not?
|
68
|
+
#
|
69
|
+
# design - or wrap lines into a Para class
|
70
|
+
# with properties lines and text
|
71
|
+
# and such - why? why not?
|
72
|
+
# downside - might be overkill/overengineered
|
73
|
+
# just use simple txt as string (buffer) for all - why? why not?
|
74
|
+
##
|
75
|
+
## hacky alternative - add a to_text or text method to string and array - why? why not?
|
76
|
+
|
77
|
+
|
78
|
+
def each_para_text( &blk ) ## or use each_text or ? - why? why not=
|
79
|
+
each_para do |lines|
|
80
|
+
txt = lines.reduce( String.new ) do |mem,line|
|
81
|
+
mem << line; mem << "\n"; mem
|
82
|
+
end
|
83
|
+
blk.call( txt )
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end # class Outline
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
###
|
91
|
+
# add alternate alias - why? why not?
|
92
|
+
QuickMatchOutline = Outline
|
93
|
+
|
94
|
+
|
95
|
+
end ## module SportDb
|
96
|
+
|
@@ -0,0 +1,98 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
|
5
|
+
|
6
|
+
class OutlineReader
|
7
|
+
|
8
|
+
def self.debug=(value) @@debug = value; end
|
9
|
+
def self.debug?() @@debug ||= false; end
|
10
|
+
def debug?() self.class.debug?; end
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not?
|
15
|
+
txt = File.open( path, 'r:utf-8' ) {|f| f.read }
|
16
|
+
parse( txt )
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.parse( txt )
|
20
|
+
new( txt ).parse
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize( txt )
|
24
|
+
@txt = txt
|
25
|
+
end
|
26
|
+
|
27
|
+
## note: skip "decorative" only heading e.g. ========
|
28
|
+
## todo/check: find a better name e.g. HEADING_EMPTY_RE or HEADING_LINE_RE or ???
|
29
|
+
HEADING_BLANK_RE = %r{\A
|
30
|
+
={1,}
|
31
|
+
\z}x
|
32
|
+
|
33
|
+
## note: like in wikimedia markup (and markdown) all optional trailing ==== too
|
34
|
+
HEADING_RE = %r{\A
|
35
|
+
(?<marker>={1,}) ## 1. leading ======
|
36
|
+
[ ]*
|
37
|
+
(?<text>[^=]+) ## 2. text (note: for now no "inline" = allowed)
|
38
|
+
[ ]*
|
39
|
+
=* ## 3. (optional) trailing ====
|
40
|
+
\z}x
|
41
|
+
|
42
|
+
def parse
|
43
|
+
outline=[] ## outline structure
|
44
|
+
start_para = true ## start new para(graph) on new text line?
|
45
|
+
|
46
|
+
@txt.each_line do |line|
|
47
|
+
line = line.strip ## todo/fix: keep leading and trailing spaces - why? why not?
|
48
|
+
|
49
|
+
if line.empty? ## todo/fix: keep blank line nodes?? and just remove comments and process headings?! - why? why not?
|
50
|
+
start_para = true
|
51
|
+
next
|
52
|
+
end
|
53
|
+
|
54
|
+
break if line == '__END__'
|
55
|
+
|
56
|
+
next if line.start_with?( '#' ) ## skip comments too
|
57
|
+
## strip inline (until end-of-line) comments too
|
58
|
+
## e.g Eupen | KAS Eupen ## [de]
|
59
|
+
## => Eupen | KAS Eupen
|
60
|
+
## e.g bq Bonaire, BOE # CONCACAF
|
61
|
+
## => bq Bonaire, BOE
|
62
|
+
line = line.sub( /#.*/, '' ).strip
|
63
|
+
pp line if debug?
|
64
|
+
|
65
|
+
## todo/check: also use heading blank as paragraph "breaker" or treat it like a comment ?? - why? why not?
|
66
|
+
next if HEADING_BLANK_RE.match( line ) # skip "decorative" only heading e.g. ========
|
67
|
+
|
68
|
+
## note: like in wikimedia markup (and markdown) all optional trailing ==== too
|
69
|
+
if m=HEADING_RE.match( line )
|
70
|
+
start_para = true
|
71
|
+
|
72
|
+
heading_marker = m[:marker]
|
73
|
+
heading_level = heading_marker.length ## count number of = for heading level
|
74
|
+
heading = m[:text].strip
|
75
|
+
|
76
|
+
puts "heading #{heading_level} >#{heading}<" if debug?
|
77
|
+
outline << [:"h#{heading_level}", heading]
|
78
|
+
else ## assume it's a (plain/regular) text line
|
79
|
+
if start_para
|
80
|
+
outline << [:p, [line]]
|
81
|
+
start_para = false
|
82
|
+
else
|
83
|
+
node = outline[-1] ## get last entry
|
84
|
+
if node[0] == :p ## assert it's a p(aragraph) node!!!
|
85
|
+
node[1] << line ## add line to p(aragraph)
|
86
|
+
else
|
87
|
+
puts "!! ERROR - invalid outline state / format - expected p(aragraph) node; got:"
|
88
|
+
pp node
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
outline
|
95
|
+
end # method read
|
96
|
+
end # class OutlineReader
|
97
|
+
|
98
|
+
end # module SportDb
|
@@ -3,39 +3,66 @@
|
|
3
3
|
module SportDb
|
4
4
|
|
5
5
|
## shared "higher-level" outline reader
|
6
|
-
### quick version WITHOUT any validation/mapping !!!
|
6
|
+
### quick version WITHOUT any (database) validation/mapping/normalization !!!
|
7
7
|
|
8
|
-
|
8
|
+
|
9
|
+
class QuickLeagueOutline
|
9
10
|
|
10
11
|
def self.read( path )
|
11
|
-
|
12
|
-
|
13
|
-
end
|
12
|
+
nodes = OutlineReader.read( path )
|
13
|
+
new( nodes )
|
14
|
+
end
|
14
15
|
|
15
16
|
def self.parse( txt )
|
16
|
-
|
17
|
+
nodes = OutlineReader.parse( txt )
|
18
|
+
new( nodes )
|
17
19
|
end
|
18
20
|
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
|
23
|
+
def initialize( nodes )
|
24
|
+
@nodes = nodes
|
22
25
|
end
|
23
26
|
|
24
|
-
|
27
|
+
|
28
|
+
###
|
29
|
+
# use Section struct for easier access - why? why not?
|
30
|
+
## e.g. sec.league instead of sec[:league] etc.
|
31
|
+
|
32
|
+
Section = Struct.new( :league, :season, :stage, :lines ) do
|
33
|
+
def text ## for alternate line access (all-in-text string)
|
34
|
+
txt = lines.reduce( String.new ) do |mem,line|
|
35
|
+
mem << line; mem << "\n"; mem
|
36
|
+
end
|
37
|
+
txt
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def each_sec( &blk )
|
42
|
+
@secs ||= _parse
|
43
|
+
|
44
|
+
@secs.each do |sec|
|
45
|
+
blk.call( sec )
|
46
|
+
end
|
47
|
+
end
|
48
|
+
alias_method :each_section, :each_sec
|
49
|
+
|
50
|
+
|
51
|
+
def _parse
|
25
52
|
secs=[] # sec(tion)s
|
26
|
-
|
53
|
+
@nodes.each do |node|
|
27
54
|
if node[0] == :h1
|
28
55
|
## check for league (and stage) and season
|
29
56
|
heading = node[1]
|
30
|
-
values =
|
57
|
+
values = _split_league( heading )
|
31
58
|
if m=values[0].match( LEAGUE_SEASON_HEADING_RE )
|
32
59
|
puts "league >#{m[:league]}<, season >#{m[:season]}<"
|
33
60
|
|
34
|
-
secs <<
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
61
|
+
secs << Section.new( league: m[:league],
|
62
|
+
season: m[:season],
|
63
|
+
stage: values[1], ## note: defaults to nil if not present
|
64
|
+
lines: []
|
65
|
+
)
|
39
66
|
else
|
40
67
|
puts "** !!! ERROR - cannot match league and season in heading; season missing?"
|
41
68
|
pp heading
|
@@ -44,12 +71,12 @@ class QuickLeagueOutlineReader
|
|
44
71
|
elsif node[0] == :h2
|
45
72
|
## todo/check - make sure parsed h1 first
|
46
73
|
heading = node[1]
|
47
|
-
## reuse league, season from h1
|
48
|
-
secs <<
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
74
|
+
## note - reuse league, season from h1
|
75
|
+
secs << Section.new( league: secs[-1].league,
|
76
|
+
season: secs[-1].season,
|
77
|
+
stage: heading,
|
78
|
+
lines: []
|
79
|
+
)
|
53
80
|
elsif node[0] == :p ## paragraph with (text) lines
|
54
81
|
lines = node[1]
|
55
82
|
## note: skip lines if no heading seen
|
@@ -58,7 +85,8 @@ class QuickLeagueOutlineReader
|
|
58
85
|
pp lines
|
59
86
|
else
|
60
87
|
## todo/check: unroll paragraphs into lines or pass along paragraphs - why? why not?
|
61
|
-
|
88
|
+
## add paragraphs not unrolled lines - why? why not?
|
89
|
+
secs[-1].lines += lines
|
62
90
|
end
|
63
91
|
else
|
64
92
|
puts "** !!! ERROR - unknown line type; for now only heading 1 for leagues supported; sorry:"
|
@@ -67,7 +95,7 @@ class QuickLeagueOutlineReader
|
|
67
95
|
end
|
68
96
|
end
|
69
97
|
secs
|
70
|
-
end # method
|
98
|
+
end # method _parse
|
71
99
|
|
72
100
|
|
73
101
|
## split into league + season
|
@@ -81,7 +109,7 @@ class QuickLeagueOutlineReader
|
|
81
109
|
)
|
82
110
|
$}x
|
83
111
|
|
84
|
-
def
|
112
|
+
def _split_league( str ) ## todo/check: rename to parse_league(s) - why? why not?
|
85
113
|
## split into league / stage / ... e.g.
|
86
114
|
## => Österr. Bundesliga 2018/19, Regular Season
|
87
115
|
## => Österr. Bundesliga 2018/19, Championship Round
|
@@ -91,5 +119,5 @@ class QuickLeagueOutlineReader
|
|
91
119
|
values = values.map { |value| value.strip } ## remove all whitespaces
|
92
120
|
values
|
93
121
|
end
|
94
|
-
end # class
|
122
|
+
end # class QuickLeagueOutline
|
95
123
|
end # module SportDb
|
@@ -24,7 +24,7 @@ class QuickMatchReader
|
|
24
24
|
|
25
25
|
def initialize( txt )
|
26
26
|
@errors = []
|
27
|
-
@
|
27
|
+
@outline = QuickLeagueOutline.parse( txt )
|
28
28
|
end
|
29
29
|
|
30
30
|
attr_reader :errors
|
@@ -55,17 +55,15 @@ class QuickMatchReader
|
|
55
55
|
@errors = []
|
56
56
|
|
57
57
|
@data = {} # return data hash with leagues
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
stage = sec[:stage]
|
68
|
-
lines = sec[:lines]
|
58
|
+
# and seasons
|
59
|
+
# for now merge stage into matches
|
60
|
+
|
61
|
+
@outline.each_sec do |sec| ## sec(tion)s
|
62
|
+
### move season parse into outline upstream - why? why not?
|
63
|
+
season = Season.parse( sec.season ) ## convert (str) to season obj!!!
|
64
|
+
league = sec.league
|
65
|
+
stage = sec.stage
|
66
|
+
lines = sec.lines
|
69
67
|
|
70
68
|
start = if season.year?
|
71
69
|
Date.new( season.start_year, 1, 1 )
|
data/lib/sportdb/quick.rb
CHANGED
@@ -17,10 +17,17 @@ end
|
|
17
17
|
## our own code
|
18
18
|
require_relative 'quick/version'
|
19
19
|
|
20
|
-
|
20
|
+
## "generic" outline readers, documents & more
|
21
|
+
##
|
22
|
+
## todo/check - move outline reader upstream to cocos - why? why not?
|
23
|
+
## use read_outline(), parse_outline() - why? why not?
|
24
|
+
require_relative 'quick/outline_reader'
|
25
|
+
require_relative 'quick/outline'
|
26
|
+
|
27
|
+
## match & league machinery
|
21
28
|
require_relative 'quick/match_parser'
|
22
29
|
|
23
|
-
require_relative 'quick/
|
30
|
+
require_relative 'quick/quick_league_outline'
|
24
31
|
require_relative 'quick/quick_match_reader'
|
25
32
|
|
26
33
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-quick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.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: 2025-
|
11
|
+
date: 2025-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sportdb-parser
|
@@ -101,7 +101,9 @@ files:
|
|
101
101
|
- Rakefile
|
102
102
|
- lib/sportdb/quick.rb
|
103
103
|
- lib/sportdb/quick/match_parser.rb
|
104
|
-
- lib/sportdb/quick/
|
104
|
+
- lib/sportdb/quick/outline.rb
|
105
|
+
- lib/sportdb/quick/outline_reader.rb
|
106
|
+
- lib/sportdb/quick/quick_league_outline.rb
|
105
107
|
- lib/sportdb/quick/quick_match_reader.rb
|
106
108
|
- lib/sportdb/quick/version.rb
|
107
109
|
homepage: https://github.com/sportdb/sport.db
|