sportdb-parser 0.6.20 → 0.7.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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -1
  3. data/Manifest.txt +14 -8
  4. data/Rakefile +1 -1
  5. data/lib/sportdb/parser/blocktxt.rb +99 -0
  6. data/lib/sportdb/parser/lexer.rb +958 -395
  7. data/lib/sportdb/parser/lexer_buffer.rb +97 -0
  8. data/lib/sportdb/parser/lexer_tty.rb +111 -0
  9. data/lib/sportdb/parser/parser.rb +1768 -855
  10. data/lib/sportdb/parser/racc_parser.rb +1 -1
  11. data/lib/sportdb/parser/racc_tree.rb +327 -41
  12. data/lib/sportdb/parser/token-date.rb +160 -178
  13. data/lib/sportdb/parser/token-date_duration.rb +190 -0
  14. data/lib/sportdb/parser/token-geo.rb +59 -59
  15. data/lib/sportdb/parser/token-goals.rb +460 -0
  16. data/lib/sportdb/parser/token-group.rb +43 -0
  17. data/lib/sportdb/parser/token-note.rb +40 -0
  18. data/lib/sportdb/parser/token-prop.rb +70 -54
  19. data/lib/sportdb/parser/token-prop_name.rb +74 -0
  20. data/lib/sportdb/parser/token-round.rb +102 -0
  21. data/lib/sportdb/parser/token-score.rb +323 -47
  22. data/lib/sportdb/parser/token-score_fuller.rb +435 -0
  23. data/lib/sportdb/parser/token-score_legs.rb +59 -0
  24. data/lib/sportdb/parser/token-status.rb +157 -160
  25. data/lib/sportdb/parser/token-table.rb +149 -0
  26. data/lib/sportdb/parser/token-text.rb +72 -23
  27. data/lib/sportdb/parser/token-time.rb +141 -0
  28. data/lib/sportdb/parser/token.rb +242 -105
  29. data/lib/sportdb/parser/token_helpers.rb +92 -0
  30. data/lib/sportdb/parser/version.rb +2 -2
  31. data/lib/sportdb/parser.rb +24 -2
  32. metadata +18 -18
  33. data/config/rounds_de.txt +0 -125
  34. data/config/rounds_en.txt +0 -29
  35. data/config/rounds_es.txt +0 -26
  36. data/config/rounds_misc.txt +0 -25
  37. data/config/rounds_pt.txt +0 -4
  38. data/config/zones_en.txt +0 -20
  39. data/lib/sportdb/parser/lang.rb +0 -298
  40. data/lib/sportdb/parser/token-minute.rb +0 -205
@@ -30,7 +30,7 @@ def initialize( txt, debug: false )
30
30
  end
31
31
 
32
32
 
33
- def debug( value ) @debug = value; end
33
+ def debug( value ) @debug = value; end ### fix: use setter-style e.g. debug=(value) !!!
34
34
  def debug?() @debug == true; end
35
35
 
36
36
  ## debug - trace / print message
@@ -4,6 +4,7 @@
4
4
 
5
5
  class RaccMatchParser
6
6
 
7
+ =begin
7
8
  RefereeLine = Struct.new( :name, :country ) do
8
9
  def pretty_print( printer )
9
10
  printer.text( "<RefereeLine " )
@@ -12,6 +13,29 @@ RefereeLine = Struct.new( :name, :country ) do
12
13
  printer.text( ">" )
13
14
  end
14
15
  end
16
+ =end
17
+
18
+ ## support multiple referees (incl. assistant refs etc.)
19
+ RefereeLine = Struct.new( :referees ) do
20
+ def pretty_print( printer )
21
+ printer.text( "<RefereeLine " )
22
+ printer.text( self.referees.pretty_inspect )
23
+ printer.text( ">" )
24
+ end
25
+ end
26
+
27
+ Referee = Struct.new( :name, :country ) do
28
+ def to_s
29
+ buf = String.new
30
+ buf << self.name
31
+ buf << " (#{self.country})" if self.country
32
+ buf
33
+ end
34
+
35
+ def pretty_print( printer )
36
+ printer.text( to_s )
37
+ end
38
+ end
15
39
 
16
40
  AttendanceLine = Struct.new( :att ) do
17
41
  def pretty_print( printer )
@@ -29,15 +53,17 @@ PenaltiesLine = Struct.new( :penalties ) do
29
53
  end
30
54
  end
31
55
 
56
+
32
57
  Penalty = Struct.new( :name, :score, :note ) do
33
58
  def to_s
34
59
  buf = String.new
35
- buf << "#{self.score} " if self.score
60
+ buf << "#{self.score[0]}-#{self.score[1]} " if self.score
36
61
  buf << self.name
37
62
  buf << " (#{self.note})" if self.note
38
63
  buf
39
64
  end
40
65
 
66
+
41
67
  def pretty_print( printer )
42
68
  printer.text( to_s )
43
69
  end
@@ -82,11 +108,12 @@ LineupLine = Struct.new( :team, :lineup, :coach ) do
82
108
  end
83
109
 
84
110
 
85
- Lineup = Struct.new( :name, :card, :sub ) do
111
+ Lineup = Struct.new( :name, :captain, :cards, :sub ) do
86
112
  def pretty_print( printer )
87
113
  buf = String.new
88
114
  buf << self.name
89
- buf << " card=" + self.card.pretty_inspect if card
115
+ buf << " [c]" if captain
116
+ buf << " cards=" + self.cards.pretty_inspect if cards
90
117
  buf << " sub=" + self.sub.pretty_inspect if sub
91
118
  printer.text( buf )
92
119
  end
@@ -134,54 +161,171 @@ RoundDef = Struct.new( :name, :date, :duration ) do
134
161
  def pretty_print( printer )
135
162
  printer.text( "<RoundDef " )
136
163
  printer.text( self.name )
137
- printer.text( " date=" + self.date.pretty_inspect ) if date
138
- printer.text( " duration=" + self.duration.pretty_inspect ) if duration
164
+ printer.text( " date=" + self.date.pretty_inspect ) if self.date
165
+ printer.text( " duration=" + self.duration.pretty_inspect ) if self.duration
139
166
  printer.text( ">" )
140
167
  end
141
168
  end
142
169
 
143
- DateHeader = Struct.new( :date, :time, :geo, :timezone ) do
170
+ DateHeader = Struct.new( :date, :year ) do
144
171
  def pretty_print( printer )
145
172
  printer.text( "<DateHeader " )
146
- printer.text( "#{self.date.pretty_inspect}" )
147
- printer.text( " time=#{self.time.pretty_inspect}" ) if self.time
148
- printer.text( " geo=#{self.geo.pretty_inspect}" ) if self.geo
149
- printer.text( " timezone=#{self.timezone}") if self.timezone
173
+ printer.text( "#{self.date.pretty_inspect}" ) if self.date
174
+ printer.text( "#{self.year.pretty_inspect}" ) if self.year
175
+ printer.text( ">")
176
+ end
177
+ end
178
+
179
+ DateHeaderLegs = Struct.new( :date1, :date2 ) do
180
+ def pretty_print( printer )
181
+ printer.text( "<DateHeaderLegs " )
182
+ printer.text( "leg1=#{self.date1.pretty_inspect}" )
183
+ printer.text( " leg2=#{self.date2.pretty_inspect}" )
150
184
  printer.text( ">")
151
185
  end
152
186
  end
153
187
 
154
- GroupHeader = Struct.new( :name ) do
188
+
189
+
190
+ RoundOutline = Struct.new( :outline, :level ) do
155
191
  def pretty_print( printer )
156
- printer.text( "<GroupHeader " )
157
- printer.text( "#{self.name}>" )
192
+ printer.text( "<RoundOutline #{self.outline}, level=#{self.level}>" )
158
193
  end
159
194
  end
160
195
 
161
- RoundHeader = Struct.new( :names, :group ) do
196
+
197
+
198
+ class BlankLine
162
199
  def pretty_print( printer )
163
- printer.text( "<RoundHeader " )
164
- printer.text( "#{self.names.join(', ')}" )
165
- printer.text( " group=#{self.group}") if self.group
166
- printer.text( ">" )
200
+ printer.text( "<BlankLine>" )
201
+ end
202
+ end
203
+
204
+ ## todo/check - find a better name for hruler - divider? or ??? - why? why not?
205
+ class HRuler ## h(orizontal) ruler (for breaks; new scopes)
206
+ def pretty_print( printer )
207
+ printer.text( "<HRuler>" )
208
+ end
209
+ end
210
+
211
+
212
+
213
+ NoteLine = Struct.new( :text ) do
214
+ def pretty_print( printer )
215
+ printer.text( "<NoteLine #{self.text}>" )
216
+ end
217
+ end
218
+
219
+ NotaBene = Struct.new( :text ) do
220
+ def pretty_print( printer )
221
+ printer.text( "<NotaBene #{self.text}>" )
222
+ end
223
+ end
224
+
225
+
226
+ ## todo/check - rename TableHeading to TableHeader - why? why not?
227
+ TableHeading = Struct.new( :text ) do
228
+ def pretty_print( printer )
229
+ printer.text( "<TableHeading #{self.text}>" )
230
+ end
231
+ end
232
+
233
+ ## todo/check - rename TableDivider to TableRule/TableRuler/TableLine - why? why not?
234
+ TableDivider = Struct.new( :text ) do
235
+ def pretty_print( printer )
236
+ printer.text( "<TableDivider #{self.text}>" )
237
+ end
238
+ end
239
+
240
+ TableLine = Struct.new( :text ) do
241
+ def pretty_print( printer )
242
+ printer.text( "<TableLine #{self.text}>" )
243
+ end
244
+ end
245
+
246
+ TableNote = Struct.new( :text ) do
247
+ def pretty_print( printer )
248
+ printer.text( "<TableNote #{self.text}>" )
249
+ end
250
+ end
251
+
252
+
253
+
254
+ ## todo/check - use a generic Heading instead of Heading1/2/3 - why? why not?
255
+ Heading1 = Struct.new( :text ) do
256
+ def pretty_print( printer )
257
+ printer.text( "<Heading1 #{self.text}>" )
167
258
  end
168
259
  end
169
260
 
261
+ Heading2 = Struct.new( :text ) do
262
+ def pretty_print( printer )
263
+ printer.text( "<Heading2 #{self.text}>" )
264
+ end
265
+ end
170
266
 
171
- RoundOutline = Struct.new( :outline ) do
267
+ Heading3 = Struct.new( :text ) do
172
268
  def pretty_print( printer )
173
- printer.text( "<RoundOutline #{self.outline}>" )
269
+ printer.text( "<Heading3 #{self.text}>" )
174
270
  end
175
271
  end
176
272
 
177
273
 
178
- MatchLine = Struct.new( :ord, :date, :time, :wday,
274
+
275
+ MatchLineBye = Struct.new( :team, :note ) do
276
+ def pretty_print( printer )
277
+ printer.text( "<MatchLineBye " )
278
+ printer.text( "#{self.team} bye")
279
+ printer.text( " note=#{self.note.pretty_inspect}" ) if self.note
280
+ printer.text( ">" )
281
+ end
282
+ end
283
+
284
+ MatchLineWalkover = Struct.new( :team1, :team2, :note ) do
285
+ def pretty_print( printer )
286
+ printer.text( "<MatchLineWalkover " )
287
+ printer.text( "#{self.team1} w/o #{self.team2}")
288
+ printer.text( " note=#{self.note.pretty_inspect}" ) if self.note
289
+ printer.text( ">" )
290
+ end
291
+ end
292
+
293
+ MatchLineLegs = Struct.new( :team1, :team2,
294
+ :score ) do ## change to geos - why? why not?
295
+ def pretty_print( printer )
296
+ printer.text( "<MatchLineLegs " )
297
+ printer.text( "#{self.team1} v #{self.team2}")
298
+ printer.breakable
299
+
300
+ members.zip(values) do |name, value|
301
+ next if [:team1, :team2].include?( name )
302
+ next if value.nil?
303
+
304
+ printer.text( "#{name}=#{value.pretty_inspect}" )
305
+ end
306
+
307
+ printer.text( ">" )
308
+ end
309
+ end
310
+
311
+
312
+ #
313
+ # note: use two status attributes for now
314
+ # 1) inline_status and 2) (note_)status
315
+ # for now e.g. A abd. B vs A v B [abadoned]
316
+ # A 3-0 awd B vs A 3-0 B [awarded]
317
+ # note - BOTH might be present at the same time
318
+
319
+
320
+ MatchLine = Struct.new( :header, :tty, ## tty = TELETYPE MODE for teams and score!!
321
+ :num, :date, :time, :time_local, :year,
179
322
  :team1, :team2,
180
- :score, :score_note,
181
- :status,
323
+ :score,
324
+ :status, :status_inline, :status_note,
182
325
  :geo,
183
- :timezone,
184
- :note ) do ## change to geos - why? why not?
326
+ :neutral, ## true/false - NOT -home/away - neutral ground
327
+ :note,
328
+ :att ) do ## change to geos - why? why not?
185
329
 
186
330
  def pretty_print( printer )
187
331
  printer.text( "<MatchLine " )
@@ -200,6 +344,59 @@ MatchLine = Struct.new( :ord, :date, :time, :wday,
200
344
 
201
345
  end
202
346
 
347
+
348
+ GoalLine = Struct.new( :goals1, :goals2 ) do
349
+ def pretty_print( printer )
350
+ printer.text( "<GoalLine " )
351
+ printer.text( "goals1=" + self.goals1.pretty_inspect + "," )
352
+ printer.breakable
353
+ printer.text( "goals2=" + self.goals2.pretty_inspect + ">" )
354
+ end
355
+
356
+ ## def clone
357
+ ## _clone = GoalLine.new( goals1: goals1.clone,
358
+ ## goals2: goals2.clone )
359
+ ##
360
+ ## puts "[debug] clone #{self.pretty_inspect} => #{_clone.pretty_inspect}"
361
+ ##
362
+ ## _clone
363
+ ## end
364
+ end
365
+
366
+
367
+ ###
368
+ ## change/rename Goal to GoalScorer - why? why not?
369
+
370
+ Goal = Struct.new( :player, :minutes, :count ) do
371
+ def to_s
372
+ buf = String.new
373
+ buf << "#{self.player}"
374
+ if count
375
+ buf << (" " + count.pretty_inspect + ",")
376
+ else
377
+ if minutes.nil? || minutes.empty?
378
+ ## add nothing if no minutes available/present
379
+ else
380
+ buf << " "
381
+ buf << minutes.map { |min| min.to_s }.join(' ')
382
+ end
383
+ end
384
+ buf
385
+ end
386
+
387
+ def pretty_print( printer )
388
+ printer.text( to_s )
389
+ end
390
+
391
+ ## def clone
392
+ ## puts "[debug] clone #{self.pretty_inspect}"
393
+ ## Goal.new( player: player.clone,
394
+ ## minutes: minutes.clone,
395
+ ## count: count.clone )
396
+ ## end
397
+ end
398
+
399
+
203
400
  ## check - use a different name e.g. GoalLineScore or such - why? why not?
204
401
  GoalLineAlt = Struct.new( :goals ) do
205
402
  def pretty_print( printer )
@@ -208,12 +405,19 @@ GoalLineAlt = Struct.new( :goals ) do
208
405
  end
209
406
  end
210
407
 
211
- GoalAlt = Struct.new( :score, :player, :minute ) do
408
+
409
+ ##
410
+ ## score and player REQUIRED
411
+ ## note - (goal) minute is optional
412
+ ## if no minute goal type is optional e.g. "standalone" (p), (og), etc.
413
+
414
+ GoalAlt = Struct.new( :score, :player, :minute, :goal_type ) do
212
415
  def to_s
213
416
  buf = String.new
214
- buf << "#{score} "
215
- buf << "#{self.player}"
216
- buf << " #{self.minute}" if self.minute
417
+ buf << "#{self.score[0]}-#{self.score[1]}"
418
+ buf << " #{self.player}"
419
+ buf << " #{self.minute}" if self.minute
420
+ buf << " #{self.goal_type}" if self.goal_type
217
421
  buf
218
422
  end
219
423
 
@@ -224,42 +428,124 @@ end
224
428
 
225
429
 
226
430
 
227
- GoalLine = Struct.new( :goals1, :goals2 ) do
431
+ GoalLineCompat = Struct.new( :goals ) do
228
432
  def pretty_print( printer )
229
- printer.text( "<GoalLine " )
230
- printer.text( "goals1=" + self.goals1.pretty_inspect + "," )
231
- printer.breakable
232
- printer.text( "goals2=" + self.goals2.pretty_inspect + ">" )
433
+ printer.text( "<GoalLineCompat " )
434
+ printer.text( "goals=" + self.goals.pretty_inspect + ">" )
233
435
  end
234
436
  end
235
437
 
236
- Goal = Struct.new( :player, :minutes ) do
438
+ ##
439
+ ## minute and player REQUIRED
440
+ ## note - score (e.g. 1-1) is optional
441
+ ## goal type is optional e.g. "standalone" (p), (og), etc.
442
+
443
+ GoalCompat = Struct.new( :score, :player, :minute, :goal_type ) do
237
444
  def to_s
238
445
  buf = String.new
239
- buf << "#{self.player}"
240
- buf << " "
241
- buf << minutes.map { |min| min.to_s }.join(' ')
446
+ buf << "#{self.minute}"
447
+ buf << " #{self.player}"
448
+ buf << " #{self.goal_type}" if self.goal_type
449
+ buf << " #{self.score[0]}-#{self.score[1]}" if self.score
242
450
  buf
243
451
  end
244
452
 
245
453
  def pretty_print( printer )
246
454
  printer.text( to_s )
247
455
  end
248
-
249
456
  end
250
457
 
251
458
 
459
+
460
+ ## FIX/FIX/FIX
461
+ ## split into Minute and
462
+ ## GoalMinute (Minute+GoalType)
252
463
  ##
253
464
  ## fix - move :og, :pen to Goal if possible - why? why not?
254
465
  ## or change to GoalMinute ???
255
- Minute = Struct.new( :m, :offset, :og, :pen ) do
466
+ ##
467
+ ## fix!!! split into GoalMinute and Minute
468
+ ## goal_minute incl. :og, :pen, :freekick, :header,
469
+ ## seconds etc.
470
+ ##
471
+ ## GoalMinute = Minute + GoalType !!!
472
+
473
+ GoalMinute = Struct.new( :m, :offset, :secs,
474
+ :og, :pen, :header, :freekick,
475
+ ) do
256
476
  def to_s
257
477
  buf = String.new
258
478
  buf << "#{self.m}"
259
- buf << "+#{self.offset}" if self.offset
260
479
  buf << "'"
480
+ buf << "+#{self.offset}" if self.offset
481
+ buf << " (og)" if self.og
482
+ buf << " (pen)" if self.pen
483
+ buf << " (f)" if self.freekick
484
+ buf << " (h)" if self.header
485
+ buf << " (#{self.secs} secs)" if self.secs
486
+ buf
487
+ end
488
+
489
+ def pretty_print( printer )
490
+ printer.text( to_s )
491
+ end
492
+
493
+ ### quick hack:
494
+ ### split struct into Minute+GoalType structs
495
+ def to_minute
496
+ Minute.new( m: self.m,
497
+ offset: self.offset,
498
+ secs: self.secs )
499
+ end
500
+
501
+ def to_goal_type
502
+ if self.og || self.pen || self.header || self.freekick
503
+ GoalType.new( og: self.og,
504
+ pen: self.pen,
505
+ header: self.header,
506
+ freekick: self.freekick )
507
+ else
508
+ nil ## note - return nil; if no goal type present!!
509
+ end
510
+ end
511
+
512
+ ## def clone
513
+ ## puts "[debug] clone #{self.pretty_inspect}"
514
+ ## GoalMinute.new( m: m.clone,
515
+ ## offset: offset.clone,
516
+ ## secs: secs.clone,
517
+ ## og: og.clone,
518
+ ## pen: pen.clone,
519
+ ## header: header.clone,
520
+ ## freekick: freekick.clone )
521
+ ##
522
+ ## end
523
+ end
524
+
525
+
526
+ GoalType = Struct.new( :og, :pen, :header, :freekick ) do
527
+ def to_s
528
+ buf = String.new
261
529
  buf << "(og)" if self.og
262
530
  buf << "(pen)" if self.pen
531
+ buf << "(f)" if self.freekick
532
+ buf << "(h)" if self.header
533
+ buf
534
+ end
535
+
536
+ def pretty_print( printer )
537
+ printer.text( to_s )
538
+ end
539
+ end
540
+
541
+
542
+ Minute = Struct.new( :m, :offset, :secs ) do
543
+ def to_s
544
+ buf = String.new
545
+ buf << "#{self.m}"
546
+ buf << "'"
547
+ buf << "+#{self.offset}" if self.offset
548
+ buf << "/#{self.secs} secs" if self.secs
263
549
  buf
264
550
  end
265
551