sportdb-parser 0.7.2 → 0.8.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.
@@ -1,524 +0,0 @@
1
-
2
- ####
3
- # RaccMatchParser support machinery (incl. node classes/abstract syntax tree)
4
-
5
- class RaccMatchParser
6
-
7
- =begin
8
- RefereeLine = Struct.new( :name, :country ) do
9
- def pretty_print( printer )
10
- printer.text( "<RefereeLine " )
11
- printer.text( self.name )
12
- printer.text( " (#{self.country})" ) if self.country
13
- printer.text( ">" )
14
- end
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
39
-
40
- AttendanceLine = Struct.new( :att ) do
41
- def pretty_print( printer )
42
- printer.text( "<AttendanceLine #{self.att}>" )
43
- end
44
- end
45
-
46
-
47
-
48
- PenaltiesLine = Struct.new( :penalties ) do
49
- def pretty_print( printer )
50
- printer.text( "<PenaltiesLine " )
51
- printer.text( self.penalties.pretty_inspect )
52
- printer.text( ">" )
53
- end
54
- end
55
-
56
-
57
- Penalty = Struct.new( :name, :score, :note ) do
58
- def to_s
59
- buf = String.new
60
- buf << "#{self.score[0]}-#{self.score[1]} " if self.score
61
- buf << self.name
62
- buf << " (#{self.note})" if self.note
63
- buf
64
- end
65
-
66
-
67
- def pretty_print( printer )
68
- printer.text( to_s )
69
- end
70
- end
71
-
72
-
73
-
74
-
75
- ## find a better name for player (use bookings?) - note - red/yellow card for trainer possible
76
- CardsLine = Struct.new( :type, :bookings ) do
77
- def pretty_print( printer )
78
- printer.text( "<CardsLine " )
79
- printer.text( self.type )
80
- printer.text( " bookings=" + self.bookings.pretty_inspect )
81
- printer.text( ">" )
82
- end
83
- end
84
-
85
- Booking = Struct.new( :name, :minute ) do
86
- def to_s
87
- buf = String.new
88
- buf << "#{self.name}"
89
- buf << " #{self.minute.to_s}" if self.minute
90
- buf
91
- end
92
-
93
- def pretty_print( printer )
94
- printer.text( to_s )
95
- end
96
- end
97
-
98
-
99
-
100
- LineupLine = Struct.new( :team, :lineup, :coach ) do
101
- def pretty_print( printer )
102
- printer.text( "<LineupLine " )
103
- printer.text( self.team )
104
- printer.text( " lineup=" + self.lineup.pretty_inspect )
105
- printer.text( " coach=" + self.coach ) if self.coach
106
- printer.text( ">" )
107
- end
108
- end
109
-
110
-
111
- Lineup = Struct.new( :name, :captain, :cards, :sub ) do
112
- def pretty_print( printer )
113
- buf = String.new
114
- buf << self.name
115
- buf << " [c]" if captain
116
- buf << " cards=" + self.cards.pretty_inspect if cards
117
- buf << " sub=" + self.sub.pretty_inspect if sub
118
- printer.text( buf )
119
- end
120
- end
121
-
122
-
123
- Card = Struct.new( :name, :minute ) do
124
- def to_s
125
- buf = String.new
126
- buf << "#{self.name}"
127
- buf << " #{self.minute.to_s}" if self.minute
128
- buf
129
- end
130
-
131
- def pretty_print( printer )
132
- printer.text( to_s )
133
- end
134
- end
135
-
136
-
137
- Sub = Struct.new( :minute, :sub ) do
138
- def pretty_print( printer )
139
- buf = String.new
140
- buf << "(" ## note - possibly recursive (thus, let minute go first/print first/upfront)
141
- buf << "#{self.minute.to_s} " if self.minute
142
- buf << "#{self.sub.pretty_inspect}"
143
- buf << ")"
144
- printer.text( buf )
145
- end
146
- end
147
-
148
-
149
-
150
- GroupDef = Struct.new( :name, :teams ) do
151
- def pretty_print( printer )
152
- printer.text( "<GroupDef " )
153
- printer.text( self.name )
154
- printer.text( " teams=" + self.teams.pretty_inspect )
155
- printer.text( ">" )
156
- end
157
- end
158
-
159
-
160
- RoundDef = Struct.new( :name, :date, :duration ) do
161
- def pretty_print( printer )
162
- printer.text( "<RoundDef " )
163
- printer.text( self.name )
164
- printer.text( " date=" + self.date.pretty_inspect ) if self.date
165
- printer.text( " duration=" + self.duration.pretty_inspect ) if self.duration
166
- printer.text( ">" )
167
- end
168
- end
169
-
170
- DateHeader = Struct.new( :date, :year ) do
171
- def pretty_print( printer )
172
- printer.text( "<DateHeader " )
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}" )
184
- printer.text( ">")
185
- end
186
- end
187
-
188
-
189
-
190
- RoundOutline = Struct.new( :outline, :level ) do
191
- def pretty_print( printer )
192
- printer.text( "<RoundOutline #{self.outline}, level=#{self.level}>" )
193
- end
194
- end
195
-
196
-
197
-
198
- class BlankLine
199
- def pretty_print( printer )
200
- printer.text( "<BlankLine>" )
201
- end
202
- end
203
-
204
-
205
-
206
- NoteLine = Struct.new( :text ) do
207
- def pretty_print( printer )
208
- printer.text( "<NoteLine #{self.text}>" )
209
- end
210
- end
211
-
212
- NotaBene = Struct.new( :text ) do
213
- def pretty_print( printer )
214
- printer.text( "<NotaBene #{self.text}>" )
215
- end
216
- end
217
-
218
-
219
-
220
-
221
- ## todo/check - use a generic Heading instead of Heading1/2/3 - why? why not?
222
- Heading1 = Struct.new( :text ) do
223
- def pretty_print( printer )
224
- printer.text( "<Heading1 #{self.text}>" )
225
- end
226
- end
227
-
228
- Heading2 = Struct.new( :text ) do
229
- def pretty_print( printer )
230
- printer.text( "<Heading2 #{self.text}>" )
231
- end
232
- end
233
-
234
- Heading3 = Struct.new( :text ) do
235
- def pretty_print( printer )
236
- printer.text( "<Heading3 #{self.text}>" )
237
- end
238
- end
239
-
240
-
241
-
242
- MatchLineBye = Struct.new( :team, :note ) do
243
- def pretty_print( printer )
244
- printer.text( "<MatchLineBye " )
245
- printer.text( "#{self.team} bye")
246
- printer.text( " note=#{self.note.pretty_inspect}" ) if self.note
247
- printer.text( ">" )
248
- end
249
- end
250
-
251
- MatchLineWalkover = Struct.new( :team1, :team2, :note ) do
252
- def pretty_print( printer )
253
- printer.text( "<MatchLineWalkover " )
254
- printer.text( "#{self.team1} w/o #{self.team2}")
255
- printer.text( " note=#{self.note.pretty_inspect}" ) if self.note
256
- printer.text( ">" )
257
- end
258
- end
259
-
260
- MatchLineLegs = Struct.new( :team1, :team2,
261
- :score ) do ## change to geos - why? why not?
262
- def pretty_print( printer )
263
- printer.text( "<MatchLineLegs " )
264
- printer.text( "#{self.team1} v #{self.team2}")
265
- printer.breakable
266
-
267
- members.zip(values) do |name, value|
268
- next if [:team1, :team2].include?( name )
269
- next if value.nil?
270
-
271
- printer.text( "#{name}=#{value.pretty_inspect}" )
272
- end
273
-
274
- printer.text( ">" )
275
- end
276
- end
277
-
278
-
279
- #
280
- # note: use two status attributes for now
281
- # 1) inline_status and 2) (note_)status
282
- # for now e.g. A abd. B vs A v B [abadoned]
283
- # A 3-0 awd B vs A 3-0 B [awarded]
284
- # note - BOTH might be present at the same time
285
-
286
-
287
- MatchLine = Struct.new( :header, :tty, ## tty = TELETYPE MODE for teams and score!!
288
- :num, :date, :time, :time_local, :year,
289
- :team1, :team2,
290
- :score,
291
- :status, :status_inline, :status_note,
292
- :geo,
293
- :neutral, ## true/false - NOT -home/away - neutral ground
294
- :note,
295
- :att ) do ## change to geos - why? why not?
296
-
297
- def pretty_print( printer )
298
- printer.text( "<MatchLine " )
299
- printer.text( "#{self.team1} v #{self.team2}")
300
- printer.breakable
301
-
302
- members.zip(values) do |name, value|
303
- next if [:team1, :team2].include?( name )
304
- next if value.nil?
305
-
306
- printer.text( "#{name}=#{value.pretty_inspect}" )
307
- end
308
-
309
- printer.text( ">" )
310
- end
311
-
312
- end
313
-
314
-
315
- GoalLine = Struct.new( :goals1, :goals2 ) do
316
- def pretty_print( printer )
317
- printer.text( "<GoalLine " )
318
- printer.text( "goals1=" + self.goals1.pretty_inspect + "," )
319
- printer.breakable
320
- printer.text( "goals2=" + self.goals2.pretty_inspect + ">" )
321
- end
322
-
323
- ## def clone
324
- ## _clone = GoalLine.new( goals1: goals1.clone,
325
- ## goals2: goals2.clone )
326
- ##
327
- ## puts "[debug] clone #{self.pretty_inspect} => #{_clone.pretty_inspect}"
328
- ##
329
- ## _clone
330
- ## end
331
- end
332
-
333
-
334
- ###
335
- ## change/rename Goal to GoalScorer - why? why not?
336
-
337
- Goal = Struct.new( :player, :minutes, :count ) do
338
- def to_s
339
- buf = String.new
340
- buf << "#{self.player}"
341
- if count
342
- buf << (" " + count.pretty_inspect + ",")
343
- else
344
- if minutes.nil? || minutes.empty?
345
- ## add nothing if no minutes available/present
346
- else
347
- buf << " "
348
- buf << minutes.map { |min| min.to_s }.join(' ')
349
- end
350
- end
351
- buf
352
- end
353
-
354
- def pretty_print( printer )
355
- printer.text( to_s )
356
- end
357
-
358
- ## def clone
359
- ## puts "[debug] clone #{self.pretty_inspect}"
360
- ## Goal.new( player: player.clone,
361
- ## minutes: minutes.clone,
362
- ## count: count.clone )
363
- ## end
364
- end
365
-
366
-
367
- ## check - use a different name e.g. GoalLineScore or such - why? why not?
368
- GoalLineAlt = Struct.new( :goals ) do
369
- def pretty_print( printer )
370
- printer.text( "<GoalLineAlt " )
371
- printer.text( "goals=" + self.goals.pretty_inspect + ">" )
372
- end
373
- end
374
-
375
-
376
- ##
377
- ## score and player REQUIRED
378
- ## note - (goal) minute is optional
379
- ## if no minute goal type is optional e.g. "standalone" (p), (og), etc.
380
-
381
- GoalAlt = Struct.new( :score, :player, :minute, :goal_type ) do
382
- def to_s
383
- buf = String.new
384
- buf << "#{self.score[0]}-#{self.score[1]}"
385
- buf << " #{self.player}"
386
- buf << " #{self.minute}" if self.minute
387
- buf << " #{self.goal_type}" if self.goal_type
388
- buf
389
- end
390
-
391
- def pretty_print( printer )
392
- printer.text( to_s )
393
- end
394
- end
395
-
396
-
397
-
398
- GoalLineCompat = Struct.new( :goals ) do
399
- def pretty_print( printer )
400
- printer.text( "<GoalLineCompat " )
401
- printer.text( "goals=" + self.goals.pretty_inspect + ">" )
402
- end
403
- end
404
-
405
- ##
406
- ## minute and player REQUIRED
407
- ## note - score (e.g. 1-1) is optional
408
- ## goal type is optional e.g. "standalone" (p), (og), etc.
409
-
410
- GoalCompat = Struct.new( :score, :player, :minute, :goal_type ) do
411
- def to_s
412
- buf = String.new
413
- buf << "#{self.minute}"
414
- buf << " #{self.player}"
415
- buf << " #{self.goal_type}" if self.goal_type
416
- buf << " #{self.score[0]}-#{self.score[1]}" if self.score
417
- buf
418
- end
419
-
420
- def pretty_print( printer )
421
- printer.text( to_s )
422
- end
423
- end
424
-
425
-
426
-
427
- ## FIX/FIX/FIX
428
- ## split into Minute and
429
- ## GoalMinute (Minute+GoalType)
430
- ##
431
- ## fix - move :og, :pen to Goal if possible - why? why not?
432
- ## or change to GoalMinute ???
433
- ##
434
- ## fix!!! split into GoalMinute and Minute
435
- ## goal_minute incl. :og, :pen, :freekick, :header,
436
- ## seconds etc.
437
- ##
438
- ## GoalMinute = Minute + GoalType !!!
439
-
440
- GoalMinute = Struct.new( :m, :offset, :secs,
441
- :og, :pen, :header, :freekick,
442
- ) do
443
- def to_s
444
- buf = String.new
445
- buf << "#{self.m}"
446
- buf << "'"
447
- buf << "+#{self.offset}" if self.offset
448
- buf << "(og)" if self.og
449
- buf << "(p)" if self.pen
450
- buf << "(f)" if self.freekick
451
- buf << "(h)" if self.header
452
- buf << " (#{self.secs} secs)" if self.secs
453
- buf
454
- end
455
-
456
- def pretty_print( printer )
457
- printer.text( to_s )
458
- end
459
-
460
- ### quick hack:
461
- ### split struct into Minute+GoalType structs
462
- def to_minute
463
- Minute.new( m: self.m,
464
- offset: self.offset,
465
- secs: self.secs )
466
- end
467
-
468
- def to_goal_type
469
- if self.og || self.pen || self.header || self.freekick
470
- GoalType.new( og: self.og,
471
- pen: self.pen,
472
- header: self.header,
473
- freekick: self.freekick )
474
- else
475
- nil ## note - return nil; if no goal type present!!
476
- end
477
- end
478
-
479
- ## def clone
480
- ## puts "[debug] clone #{self.pretty_inspect}"
481
- ## GoalMinute.new( m: m.clone,
482
- ## offset: offset.clone,
483
- ## secs: secs.clone,
484
- ## og: og.clone,
485
- ## pen: pen.clone,
486
- ## header: header.clone,
487
- ## freekick: freekick.clone )
488
- ##
489
- ## end
490
- end
491
-
492
-
493
- GoalType = Struct.new( :og, :pen, :header, :freekick ) do
494
- def to_s
495
- buf = String.new
496
- buf << "(og)" if self.og
497
- buf << "(pen)" if self.pen
498
- buf << "(f)" if self.freekick
499
- buf << "(h)" if self.header
500
- buf
501
- end
502
-
503
- def pretty_print( printer )
504
- printer.text( to_s )
505
- end
506
- end
507
-
508
-
509
- Minute = Struct.new( :m, :offset, :secs ) do
510
- def to_s
511
- buf = String.new
512
- buf << "#{self.m}"
513
- buf << "'"
514
- buf << "+#{self.offset}" if self.offset
515
- buf << "/#{self.secs} secs" if self.secs
516
- buf
517
- end
518
-
519
- def pretty_print( printer )
520
- printer.text( to_s )
521
- end
522
- end
523
-
524
- end # class RaccMatchParser