sportdb 1.6.5 → 1.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/Manifest.txt +4 -0
- data/lib/sportdb/lang.rb +13 -10
- data/lib/sportdb/reader.rb +19 -6
- data/lib/sportdb/utils.rb +60 -40
- data/lib/sportdb/version.rb +1 -1
- data/test/helper.rb +16 -0
- data/test/test_lang.rb +118 -0
- data/test/test_round.rb +170 -0
- data/test/test_utils.rb +57 -0
- metadata +19 -11
data/.gemtest
ADDED
File without changes
|
data/Manifest.txt
CHANGED
data/lib/sportdb/lang.rb
CHANGED
@@ -72,7 +72,7 @@ class Lang
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def knockout_round
|
75
|
-
@
|
75
|
+
@knockout_round ||= knockout_round_getter
|
76
76
|
end
|
77
77
|
|
78
78
|
def leg1
|
@@ -103,21 +103,21 @@ class Lang
|
|
103
103
|
def regex_leg2
|
104
104
|
@regex_leg2 ||= regex_leg2_getter
|
105
105
|
end
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
|
109
107
|
private
|
110
108
|
def group_getter
|
111
109
|
h = @fixtures[ lang ]
|
112
|
-
values =
|
110
|
+
values = "" # NB: always construct a new string (do NOT use a reference to hash value)
|
111
|
+
values << h['group']
|
113
112
|
values
|
114
113
|
end
|
115
|
-
|
114
|
+
|
116
115
|
def round_getter
|
117
116
|
# e.g. Spieltag|Runde|Achtelfinale|Viertelfinale|Halbfinale|Finale
|
118
117
|
|
119
118
|
h = @fixtures[ lang ]
|
120
|
-
values =
|
119
|
+
values = "" # NB: always construct a new string (do NOT use a reference to hash value)
|
120
|
+
values << h['round']
|
121
121
|
values << "|" << h['matchday'] ## todo/check: fold round n matchday into one key? why? why not??
|
122
122
|
|
123
123
|
### add knockout rounds values too
|
@@ -132,19 +132,22 @@ private
|
|
132
132
|
|
133
133
|
def leg1_getter
|
134
134
|
h = @fixtures[ lang ]
|
135
|
-
values =
|
135
|
+
values = "" # NB: always construct a new string (do NOT use a reference to hash value)
|
136
|
+
values << h['leg1']
|
136
137
|
values
|
137
138
|
end
|
138
139
|
|
139
140
|
def leg2_getter
|
140
141
|
h = @fixtures[ lang ]
|
141
|
-
values =
|
142
|
+
values = "" # NB: always construct a new string (do NOT use a reference to hash value)
|
143
|
+
values << h['leg2']
|
142
144
|
values
|
143
145
|
end
|
144
146
|
|
145
147
|
def knockout_round_getter
|
146
148
|
h = @fixtures[ lang ]
|
147
|
-
values =
|
149
|
+
values = "" # NB: always construct a new string (do NOT use a reference to hash value)
|
150
|
+
values << h['round32']
|
148
151
|
values << "|" << h['round16']
|
149
152
|
values << "|" << h['quarterfinals']
|
150
153
|
values << "|" << h['semifinals']
|
data/lib/sportdb/reader.rb
CHANGED
@@ -475,12 +475,23 @@ private
|
|
475
475
|
|
476
476
|
def parse_round( line )
|
477
477
|
logger.debug "parsing round line: >#{line}<"
|
478
|
-
|
479
|
-
|
480
|
-
|
478
|
+
|
479
|
+
### todo/fix/check: move cut off optional comment in reader for all lines? why? why not?
|
480
|
+
cut_off_end_of_line_comment!( line ) # cut off optional comment starting w/ #
|
481
|
+
|
482
|
+
# NB: cut off optional title2 starting w/ // first
|
483
|
+
title2 = find_round_title2!( line )
|
481
484
|
|
482
485
|
group_title, group_pos = find_group_title_and_pos!( line )
|
483
486
|
|
487
|
+
pos = find_round_pos!( line )
|
488
|
+
|
489
|
+
title = find_round_title!( line )
|
490
|
+
|
491
|
+
## NB: use extracted round title for knockout check
|
492
|
+
@knockout_flag = is_knockout_round?( title )
|
493
|
+
|
494
|
+
|
484
495
|
if group_pos.present?
|
485
496
|
@group = Group.find_by_event_id_and_pos!( @event.id, group_pos )
|
486
497
|
else
|
@@ -491,12 +502,14 @@ private
|
|
491
502
|
|
492
503
|
## NB: dummy/placeholder start_at, end_at date
|
493
504
|
## replace/patch after adding all games for round
|
494
|
-
|
505
|
+
|
495
506
|
round_attribs = {
|
496
|
-
title:
|
507
|
+
title: title,
|
508
|
+
title2: title2,
|
509
|
+
knockout: @knockout_flag
|
497
510
|
}
|
498
511
|
|
499
|
-
|
512
|
+
|
500
513
|
@round = Round.find_by_event_id_and_pos( @event.id, pos )
|
501
514
|
if @round.present?
|
502
515
|
logger.debug "update round #{@round.id}:"
|
data/lib/sportdb/utils.rb
CHANGED
@@ -20,9 +20,9 @@ module SportDb::FixtureHelpers
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def is_knockout_round?( line )
|
23
|
-
|
23
|
+
|
24
24
|
## todo: check for adding ignore case for regex (e.g. 1st leg/1st Leg)
|
25
|
-
|
25
|
+
|
26
26
|
if line =~ SportDb.lang.regex_leg1
|
27
27
|
logger.debug " two leg knockout; skip knockout flag on first leg"
|
28
28
|
false
|
@@ -73,57 +73,77 @@ module SportDb::FixtureHelpers
|
|
73
73
|
|
74
74
|
return [title,pos]
|
75
75
|
end
|
76
|
-
|
77
|
-
def
|
78
|
-
|
79
|
-
## todo: let title2 go first to cut off //
|
80
|
-
## todo: cut of end of line comments w/ # ???
|
76
|
+
|
77
|
+
def cut_off_end_of_line_comment!( line )
|
78
|
+
# cut off (that is, remove) optional end of line comment starting w/ #
|
81
79
|
|
82
|
-
|
83
|
-
|
80
|
+
line = line.sub( /#.*$/, '' )
|
81
|
+
line
|
82
|
+
end
|
84
83
|
|
85
|
-
|
86
|
-
|
87
|
-
|
84
|
+
|
85
|
+
def find_round_title2!( line )
|
86
|
+
# assume everything after // is title2 - strip off leading n trailing whitespaces
|
87
|
+
regex = /\/{2,}\s*(.+)\s*$/
|
88
88
|
if line =~ regex
|
89
|
-
logger.debug "
|
89
|
+
logger.debug " title2: >#{$1}<"
|
90
90
|
|
91
|
-
line.sub!( regex, '[ROUND|
|
92
|
-
return $1
|
91
|
+
line.sub!( regex, '[ROUND|TITLE2]' )
|
92
|
+
return $1
|
93
|
+
else
|
94
|
+
return nil # no round title2 found (title2 is optional)
|
93
95
|
end
|
96
|
+
end
|
94
97
|
|
95
|
-
# continue; try some other options
|
96
98
|
|
97
|
-
|
98
|
-
#
|
99
|
-
#
|
100
|
-
# e.g. Viertelfinale // Di+Mi 10.+11. April 2012 becomes just
|
101
|
-
# Viertelfinale
|
102
|
-
|
103
|
-
cutoff_regex = /^(.+?)[ \t]\/{1,3}[ \t]/
|
104
|
-
|
105
|
-
if line =~ cutoff_regex
|
106
|
-
line = $1.to_s # cut off the rest if regex matches
|
107
|
-
end
|
99
|
+
def find_round_title!( line )
|
100
|
+
# assume everything left is the round title
|
101
|
+
# extract all other items first (round title2, round pos, group title n pos, etc.)
|
108
102
|
|
109
|
-
|
110
|
-
|
111
|
-
# e.g. Jornada 3 // 1,2 y 3 febrero
|
112
|
-
# only replaces match in local string w/ [ROUND|POS]
|
103
|
+
buf = line.dup
|
104
|
+
logger.debug " find_round_title! line-before: >>#{buf}<<"
|
113
105
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
106
|
+
buf.gsub!( /\[.+?\]/, '' ) # e.g. remove [ROUND|POS], [ROUND|TITLE2], [GROUP|TITLE+POS] etc.
|
107
|
+
buf.sub!( /\s+[\/\-]{1,}\s+$/, '' ) # remove optional trailing / or / chars (left over from group)
|
108
|
+
buf.strip! # remove leading and trailing whitespace
|
109
|
+
|
110
|
+
logger.debug " find_round_title! line-after: >>#{buf}<<"
|
111
|
+
|
112
|
+
### bingo - assume what's left is the round title
|
113
|
+
|
114
|
+
logger.debug " title: >>#{buf}<<"
|
115
|
+
line.sub!( buf, '[ROUND|TITLE]' )
|
121
116
|
|
122
|
-
|
117
|
+
buf
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
def find_round_pos!( line )
|
122
|
+
## fix/todo:
|
123
|
+
## if no round found assume last_pos+1 ??? why? why not?
|
124
|
+
|
125
|
+
# extract optional round pos from line
|
126
|
+
# e.g. (1) - must start line
|
127
|
+
regex_pos = /^[ \t]*\((\d{1,3})\)[ \t]+/
|
128
|
+
|
129
|
+
## find free standing number
|
130
|
+
regex_num = /\b(\d{1,3})\b/
|
131
|
+
|
132
|
+
if line =~ regex_pos
|
133
|
+
logger.debug " pos: >#{$1}<"
|
134
|
+
|
135
|
+
line.sub!( regex_pos, '[ROUND|POS] ' ) ## NB: add back trailing space that got swallowed w/ regex -> [ \t]+
|
136
|
+
return $1.to_i
|
137
|
+
elsif line =~ regex_num
|
138
|
+
## assume number in title is pos (e.g. Jornada 3, 3 Runde etc.)
|
139
|
+
## NB: do NOT remove pos from string (will get removed by round title)
|
140
|
+
logger.debug " pos: >#{$1}<"
|
141
|
+
return $1.to_i
|
123
142
|
else
|
143
|
+
## fix: add logger.warn no round pos found in line
|
124
144
|
return nil
|
125
145
|
end
|
126
|
-
end
|
146
|
+
end # method find_round_pos!
|
127
147
|
|
128
148
|
def find_date!( line )
|
129
149
|
# extract date from line
|
data/lib/sportdb/version.rb
CHANGED
data/test/helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
## $:.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
## minitest setup
|
5
|
+
|
6
|
+
# require 'minitest/unit'
|
7
|
+
require 'minitest/autorun'
|
8
|
+
|
9
|
+
# include MiniTest::Unit # lets us use TestCase instead of MiniTest::Unit::TestCase
|
10
|
+
|
11
|
+
|
12
|
+
## our own code
|
13
|
+
|
14
|
+
require 'logutils'
|
15
|
+
require 'sportdb'
|
16
|
+
|
data/test/test_lang.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_lang.rb
|
6
|
+
# or better
|
7
|
+
# rake -I ./lib test
|
8
|
+
|
9
|
+
require 'helper'
|
10
|
+
|
11
|
+
class TestLang < MiniTest::Unit::TestCase
|
12
|
+
|
13
|
+
def test_getters
|
14
|
+
|
15
|
+
lang = SportDb.lang
|
16
|
+
lang.lang = 'en'
|
17
|
+
|
18
|
+
group = 'Group'
|
19
|
+
|
20
|
+
round = 'Round'
|
21
|
+
round << '|Matchday'
|
22
|
+
round << '|Round of 32|Last 32'
|
23
|
+
round << '|Round of 16|Last 16'
|
24
|
+
round << '|Quarterfinals|Quarter-finals|Quarters|Quarterfinal'
|
25
|
+
round << '|Semifinals|Semi-finals|Semis'
|
26
|
+
round << '|Third-place play-off|Third place play-off|Third place|3rd place match'
|
27
|
+
round << '|Final|Finals'
|
28
|
+
|
29
|
+
knockout_round = 'Round of 32|Last 32'
|
30
|
+
knockout_round << '|Round of 16|Last 16'
|
31
|
+
knockout_round << '|Quarterfinals|Quarter-finals|Quarters|Quarterfinal'
|
32
|
+
knockout_round << '|Semifinals|Semi-finals|Semis'
|
33
|
+
knockout_round << '|Third-place play-off|Third place play-off|Third place|3rd place match'
|
34
|
+
knockout_round << '|Final|Finals'
|
35
|
+
|
36
|
+
|
37
|
+
assert( group == lang.group )
|
38
|
+
assert( round == lang.round )
|
39
|
+
assert( knockout_round == lang.knockout_round )
|
40
|
+
|
41
|
+
# NB: call twice to test caching with ||=
|
42
|
+
assert( group == lang.group )
|
43
|
+
assert( round == lang.round )
|
44
|
+
assert( knockout_round == lang.knockout_round )
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_getters_de
|
49
|
+
lang = SportDb.lang
|
50
|
+
lang.lang = 'de'
|
51
|
+
|
52
|
+
group = 'Gruppe'
|
53
|
+
|
54
|
+
round = 'Runde'
|
55
|
+
round << '|Spieltag'
|
56
|
+
round << '|Sechzehntelfinale|1/16 Finale'
|
57
|
+
round << '|Achtelfinale|1/8 Finale'
|
58
|
+
round << '|Viertelfinale|1/4 Finale'
|
59
|
+
round << '|Halbfinale|Semifinale|1/2 Finale'
|
60
|
+
round << '|Spiel um Platz 3'
|
61
|
+
round << '|Finale|Endspiel'
|
62
|
+
|
63
|
+
knockout_round = 'Sechzehntelfinale|1/16 Finale'
|
64
|
+
knockout_round << '|Achtelfinale|1/8 Finale'
|
65
|
+
knockout_round << '|Viertelfinale|1/4 Finale'
|
66
|
+
knockout_round << '|Halbfinale|Semifinale|1/2 Finale'
|
67
|
+
knockout_round << '|Spiel um Platz 3'
|
68
|
+
knockout_round << '|Finale|Endspiel'
|
69
|
+
|
70
|
+
|
71
|
+
assert( group == lang.group )
|
72
|
+
assert( round == lang.round )
|
73
|
+
assert( knockout_round == lang.knockout_round )
|
74
|
+
|
75
|
+
# NB: call twice to test caching with ||=
|
76
|
+
|
77
|
+
assert( round == lang.round )
|
78
|
+
assert( group == lang.group )
|
79
|
+
assert( knockout_round == lang.knockout_round )
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_regex_knockout_round
|
83
|
+
lang = SportDb.lang
|
84
|
+
lang.lang = 'en'
|
85
|
+
|
86
|
+
lines = [
|
87
|
+
'(4) Quarter-finals',
|
88
|
+
'(5) Semi-finals',
|
89
|
+
'(6) Final'
|
90
|
+
]
|
91
|
+
|
92
|
+
lines.each do |line|
|
93
|
+
assert( line =~ lang.regex_knockout_round )
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_regex_knockout_round_de
|
99
|
+
lang = SportDb.lang
|
100
|
+
lang.lang = 'de'
|
101
|
+
|
102
|
+
lines = [
|
103
|
+
'(1) Achtelfinale // Di+Mi 14.+15. & 21.+22. Feb 2012',
|
104
|
+
'(2) Achtelfinale Rückspiele // Di+Mi 6.+7. & 13.+14. März 2012',
|
105
|
+
'(3) Viertelfinale // Di+Mi 27.+28. März 2012',
|
106
|
+
'(4) Viertelfinale Rückspiele // Di+Mi 3.+4. April 2012',
|
107
|
+
'(5) Halbfinale // Di+Mi 17.+18. April 2012',
|
108
|
+
'(6) Halbfinale Rückspiele // Di+Mi 24.+25. April 2012',
|
109
|
+
'(7) Finale // Sa 19. Mai 2012'
|
110
|
+
]
|
111
|
+
|
112
|
+
lines.each do |line|
|
113
|
+
assert( line =~ lang.regex_knockout_round )
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end # class TestLang
|
data/test/test_round.rb
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_lang.rb
|
6
|
+
# or better
|
7
|
+
# rake -I ./lib test
|
8
|
+
|
9
|
+
require 'helper'
|
10
|
+
|
11
|
+
class TestRound < MiniTest::Unit::TestCase
|
12
|
+
|
13
|
+
|
14
|
+
def test_round_en
|
15
|
+
SportDb.lang.lang = 'en'
|
16
|
+
|
17
|
+
line = "2. Round / Group B"
|
18
|
+
|
19
|
+
pos, title, title2, group_pos, group_title, ko = parse_round( line )
|
20
|
+
|
21
|
+
assert( pos == 2 )
|
22
|
+
assert( title == "2. Round" )
|
23
|
+
assert( title2 == nil )
|
24
|
+
assert( ko == false )
|
25
|
+
|
26
|
+
line = "(1) Matchday P.1 / 1st Leg // January 22-24"
|
27
|
+
|
28
|
+
pos, title, title2, group_pos, group_title, ko = parse_round( line )
|
29
|
+
|
30
|
+
assert( pos == 1 )
|
31
|
+
assert( title == "Matchday P.1 / 1st Leg" )
|
32
|
+
assert( title2 == "January 22-24" )
|
33
|
+
assert( ko == false )
|
34
|
+
|
35
|
+
line = "(4) Matchday 2 / Group 1 // February 19-21"
|
36
|
+
|
37
|
+
pos, title, title2, group_pos, group_title, ko = parse_round( line )
|
38
|
+
|
39
|
+
assert( pos == 4 )
|
40
|
+
assert( title == "Matchday 2" )
|
41
|
+
assert( title2 == "February 19-21" )
|
42
|
+
assert( ko == false )
|
43
|
+
|
44
|
+
line = "(13) Round of 16 / 1st Leg // April 25, May 1-3"
|
45
|
+
|
46
|
+
pos, title, title2, group_pos, group_title, ko = parse_round( line )
|
47
|
+
|
48
|
+
assert( pos == 13 )
|
49
|
+
assert( title == "Round of 16 / 1st Leg" )
|
50
|
+
assert( title2 == "April 25, May 1-3" )
|
51
|
+
assert( ko == false ) # NB: 1st Leg is NOT k.o. (only 2nd Leg)
|
52
|
+
|
53
|
+
line = "(14) Round of 16 / 2nd Leg // May 8-10"
|
54
|
+
|
55
|
+
pos, title, title2, group_pos, group_title, ko = parse_round( line )
|
56
|
+
|
57
|
+
assert( pos == 14 )
|
58
|
+
assert( title == "Round of 16 / 2nd Leg" )
|
59
|
+
assert( title2 == "May 8-10" )
|
60
|
+
assert( ko == true )
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
def test_finals_en
|
66
|
+
SportDb.lang.lang = 'en'
|
67
|
+
|
68
|
+
line = "(4) Quarter-finals"
|
69
|
+
|
70
|
+
pos, title, title2, group_pos, group_title, ko = parse_round( line )
|
71
|
+
|
72
|
+
assert( pos == 4 )
|
73
|
+
assert( title == "Quarter-finals" )
|
74
|
+
assert( title2 == nil )
|
75
|
+
assert( ko == true )
|
76
|
+
|
77
|
+
line = "(5) Semi-finals"
|
78
|
+
|
79
|
+
pos, title, title2, group_pos, group_title, ko = parse_round( line )
|
80
|
+
|
81
|
+
assert( pos == 5 )
|
82
|
+
assert( title == "Semi-finals" )
|
83
|
+
assert( title2 == nil )
|
84
|
+
assert( ko == true )
|
85
|
+
|
86
|
+
line = "(6) Final"
|
87
|
+
|
88
|
+
pos, title, title2, group_pos, group_title, ko = parse_round( line )
|
89
|
+
|
90
|
+
assert( pos == 6 )
|
91
|
+
assert( title == "Final" )
|
92
|
+
assert( title2 == nil )
|
93
|
+
assert( ko == true )
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
def test_round_es
|
98
|
+
SportDb.lang.lang = 'es'
|
99
|
+
|
100
|
+
line = "Jornada 2 // 27, 28 y 29 de julio"
|
101
|
+
|
102
|
+
pos, title, title2, group_pos, group_title, ko = parse_round( line )
|
103
|
+
|
104
|
+
assert( pos = 2 )
|
105
|
+
assert( title == 'Jornada 2' )
|
106
|
+
assert( title2 == '27, 28 y 29 de julio' )
|
107
|
+
assert( ko == false )
|
108
|
+
|
109
|
+
line = "(18) Cuartos de Final / Ida // 14/15 de noviembre"
|
110
|
+
|
111
|
+
pos, title, title2, group_pos, group_title, ko = parse_round( line )
|
112
|
+
|
113
|
+
assert( pos = 18 )
|
114
|
+
assert( title == 'Cuartos de Final / Ida' )
|
115
|
+
assert( title2 == '14/15 de noviembre' )
|
116
|
+
assert( ko == false )
|
117
|
+
|
118
|
+
line = "(19) Cuartos de Final / Vuelta // 17/18 de noviembre"
|
119
|
+
|
120
|
+
pos, title, title2, group_pos, group_title, ko = parse_round( line )
|
121
|
+
|
122
|
+
assert( pos = 19 )
|
123
|
+
assert( title == 'Cuartos de Final / Vuelta' )
|
124
|
+
assert( title2 == '17/18 de noviembre' )
|
125
|
+
assert( ko == true )
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
def test_round_de
|
130
|
+
SportDb.lang.lang = 'de'
|
131
|
+
|
132
|
+
line = "Spieltag 5 / Gruppe A // Di./Mi., 20.+21. Nov 2012"
|
133
|
+
|
134
|
+
pos, title, title2, group_pos, group_title, ko = parse_round( line )
|
135
|
+
|
136
|
+
assert( pos = 5 )
|
137
|
+
assert( title == 'Spieltag 5' )
|
138
|
+
assert( title2 == 'Di./Mi., 20.+21. Nov 2012' )
|
139
|
+
assert( ko == false )
|
140
|
+
|
141
|
+
line = "(8) Achtelfinale Rückspiele // Di./Mi., 5.+6./12.+13. Mär 2013"
|
142
|
+
|
143
|
+
pos, title, title2, group_pos, group_title, ko = parse_round( line )
|
144
|
+
|
145
|
+
assert( pos = 8 )
|
146
|
+
assert( title == 'Achtelfinale Rückspiele' )
|
147
|
+
assert( title2 == 'Di./Mi., 5.+6./12.+13. Mär 2013' )
|
148
|
+
assert( ko == true )
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
private
|
153
|
+
class Reader
|
154
|
+
include LogUtils::Logging # add logger
|
155
|
+
include SportDb::FixtureHelpers
|
156
|
+
end
|
157
|
+
|
158
|
+
def parse_round( line )
|
159
|
+
reader = Reader.new
|
160
|
+
|
161
|
+
title2 = reader.find_round_title2!( line )
|
162
|
+
group_title, group_pos = reader.find_group_title_and_pos!( line )
|
163
|
+
pos = reader.find_round_pos!( line )
|
164
|
+
title = reader.find_round_title!( line )
|
165
|
+
knockout = reader.is_knockout_round?( title ) # NB: use title as input NOT line
|
166
|
+
|
167
|
+
[pos, title, title2, group_pos, group_title, knockout]
|
168
|
+
end
|
169
|
+
|
170
|
+
end # class TestRound
|
data/test/test_utils.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_lang.rb
|
6
|
+
# or better
|
7
|
+
# rake -I ./lib test
|
8
|
+
|
9
|
+
require 'helper'
|
10
|
+
|
11
|
+
class TestUtils < MiniTest::Unit::TestCase
|
12
|
+
|
13
|
+
|
14
|
+
class Reader
|
15
|
+
include LogUtils::Logging # add logger
|
16
|
+
include SportDb::FixtureHelpers
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_is_knockout_round
|
20
|
+
SportDb.lang.lang = 'en'
|
21
|
+
|
22
|
+
lines = [
|
23
|
+
'(4) Quarter-finals',
|
24
|
+
'(5) Semi-finals',
|
25
|
+
'(6) Final'
|
26
|
+
]
|
27
|
+
|
28
|
+
reader = Reader.new
|
29
|
+
|
30
|
+
lines.each do |line|
|
31
|
+
assert( reader.is_knockout_round?( line ) )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def test_is_knockout_round_de
|
37
|
+
SportDb.lang.lang = 'de'
|
38
|
+
|
39
|
+
lines = [
|
40
|
+
'(1) Achtelfinale // Di+Mi 14.+15. & 21.+22. Feb 2012',
|
41
|
+
'(2) Achtelfinale Rückspiele // Di+Mi 6.+7. & 13.+14. März 2012',
|
42
|
+
'(3) Viertelfinale // Di+Mi 27.+28. März 2012',
|
43
|
+
'(4) Viertelfinale Rückspiele // Di+Mi 3.+4. April 2012',
|
44
|
+
'(5) Halbfinale // Di+Mi 17.+18. April 2012',
|
45
|
+
'(6) Halbfinale Rückspiele // Di+Mi 24.+25. April 2012',
|
46
|
+
'(7) Finale // Sa 19. Mai 2012'
|
47
|
+
]
|
48
|
+
|
49
|
+
reader = Reader.new
|
50
|
+
|
51
|
+
lines.each do |line|
|
52
|
+
assert( reader.is_knockout_round?( line ) )
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end # class TestUtils
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: worlddb
|
16
|
-
requirement: &
|
16
|
+
requirement: &72206260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.6'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *72206260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: commander
|
27
|
-
requirement: &
|
27
|
+
requirement: &72206040 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 4.1.3
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *72206040
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rdoc
|
38
|
-
requirement: &
|
38
|
+
requirement: &73407120 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '3.10'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *73407120
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: hoe
|
49
|
-
requirement: &
|
49
|
+
requirement: &73406900 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '3.3'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *73406900
|
58
58
|
description: sportdb - sport.db command line tool
|
59
59
|
email: opensport@googlegroups.com
|
60
60
|
executables:
|
@@ -105,6 +105,11 @@ files:
|
|
105
105
|
- lib/sportdb/utils.rb
|
106
106
|
- lib/sportdb/version.rb
|
107
107
|
- tasks/test.rb
|
108
|
+
- test/helper.rb
|
109
|
+
- test/test_lang.rb
|
110
|
+
- test/test_round.rb
|
111
|
+
- test/test_utils.rb
|
112
|
+
- .gemtest
|
108
113
|
homepage: https://github.com/geraldb/sport.db.ruby
|
109
114
|
licenses:
|
110
115
|
- Public Domain
|
@@ -142,4 +147,7 @@ rubygems_version: 1.8.17
|
|
142
147
|
signing_key:
|
143
148
|
specification_version: 3
|
144
149
|
summary: sportdb - sport.db command line tool
|
145
|
-
test_files:
|
150
|
+
test_files:
|
151
|
+
- test/test_lang.rb
|
152
|
+
- test/test_round.rb
|
153
|
+
- test/test_utils.rb
|