sportdb-formats 1.2.0 → 2.0.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,90 +0,0 @@
1
-
2
- module SportDb
3
- module ParserHelper
4
-
5
-
6
- def read_lines( txt ) ## todo/check: add alias preproc_lines or build_lines or prep_lines etc. - why? why not?
7
- ## returns an array of lines with comments and empty lines striped / removed
8
- lines = []
9
- txt.each_line do |line| ## preprocess
10
- line = line.strip
11
-
12
- next if line.empty? || line.start_with?('#') ### skip empty lines and comments
13
- line = line.sub( /#.*/, '' ).strip ### cut-off end-of line comments too
14
- lines << line
15
- end
16
- lines
17
- end
18
-
19
-
20
- def is_round?( line )
21
- ## note: =~ returns nil if not match found, and 0,1, etc for match
22
-
23
- ## note: allow "free standing" leg 1 and leg 2 too
24
- ## (e.g. Hinspiel, Rückspiel etc. used for now in Relegation, for example)
25
- ## note ONLY allowed if "free standing", that is, full line with nothing else
26
- ## use "custom" regex for special case for now
27
- ## avoids match HIN in PascHINg, for example (hin in german for leg 1)
28
- line =~ SportDb.lang.regex_round ||
29
- line =~ /^(#{SportDb.lang.leg1})$/i ||
30
- line =~ /^(#{SportDb.lang.leg2})$/i
31
- end
32
-
33
-
34
- def is_knockout_round?( line )
35
-
36
- ## todo: check for adding ignore case for regex (e.g. 1st leg/1st Leg)
37
-
38
- if line =~ SportDb.lang.regex_leg1
39
- logger.debug " two leg knockout; skip knockout flag on first leg"
40
- false
41
- elsif line =~ SportDb.lang.regex_knockout_round
42
- logger.debug " setting knockout flag to true"
43
- true
44
- elsif line =~ /K\.O\.|K\.o\.|Knockout/
45
- ## NB: add two language independent markers, that is, K.O. and Knockout
46
- logger.debug " setting knockout flag to true (lang independent marker)"
47
- true
48
- else
49
- false
50
- end
51
- end
52
-
53
- def is_round_def?( line )
54
- ## must include bar (|) marker (make required)
55
- ## todo/fix: use split('|') and check is_round? only on left hand side!!!! not whole line
56
- line =~ /\|/ && is_round?( line )
57
- end
58
-
59
-
60
-
61
-
62
- def is_group?( line )
63
- # note: check after is_round? (round may contain group reference!)
64
- ## note: =~ return nil if not match found, and 0,1, etc for match
65
- (line =~ SportDb.lang.regex_group) != nil
66
- end
67
-
68
- def is_group_def?( line )
69
- # note: check after is_round? (round may contain group reference!)
70
- ## must include bar (|) marker (make required)
71
- ## todo/fix: use split('|') and check is_round? only on left hand side!!!! not whole line
72
- line =~ /\|/ && is_group?( line )
73
- end
74
-
75
-
76
- def is_goals?( line )
77
- # check if is goals line
78
- # e.g. looks like
79
- # Neymar 29', 71' (pen.) Oscar 90+1'; Marcelo 11' (o.g.)
80
- # check for
81
- # <space>90' or
82
- # <space>90+1'
83
-
84
- line =~ /[ ](\d{1,3}\+)?\d{1,3}'/
85
- end
86
-
87
-
88
- end # module ParserHelper
89
- end # module SportDb
90
-