sportdb 1.8.9 → 1.8.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -106,8 +106,19 @@ class GameReader
106
106
  end # method load_fixtures
107
107
 
108
108
 
109
- def parse_group( line )
110
- logger.debug "parsing group line: >#{line}<"
109
+
110
+ def parse_group_header( line )
111
+ logger.debug "parsing group header line: >#{line}<"
112
+
113
+ title, pos = find_group_title_and_pos!( line )
114
+
115
+ logger.debug " title: >#{title}<"
116
+ logger.debug " pos: >#{pos}<"
117
+ logger.debug " line: >#{line}<"
118
+ end
119
+
120
+ def parse_group_def( line )
121
+ logger.debug "parsing group def line: >#{line}<"
111
122
 
112
123
  match_teams!( line )
113
124
  team_keys = find_teams!( line )
@@ -144,9 +155,29 @@ class GameReader
144
155
  @group.teams << team
145
156
  end
146
157
  end
147
-
148
- def parse_round( line )
149
- logger.debug "parsing round line: >#{line}<"
158
+
159
+
160
+ def parse_round_def( line )
161
+ logger.debug "parsing round def line: >#{line}<"
162
+
163
+ start_at = find_date!( line, start_at: @event.start_at )
164
+ end_at = find_date!( line, start_at: @event.start_at )
165
+
166
+ # note: if end_at nil? -- assume start_at == end_at
167
+
168
+ ## pos = find_round_pos!( line )
169
+ ## title = find_round_title!( line )
170
+
171
+ logger.debug " start_at: #{start_at}"
172
+ logger.debug " end_at: #{end_at}"
173
+
174
+ logger.debug " line: >#{line}<"
175
+ end
176
+
177
+
178
+
179
+ def parse_round_header( line )
180
+ logger.debug "parsing round header line: >#{line}<"
150
181
 
151
182
  ### todo/fix/check: move cut off optional comment in reader for all lines? why? why not?
152
183
  cut_off_end_of_line_comment!( line ) # cut off optional comment starting w/ #
@@ -154,6 +185,8 @@ class GameReader
154
185
  # NB: cut off optional title2 starting w/ // first
155
186
  title2 = find_round_title2!( line )
156
187
 
188
+ # todo/fix: check if it is possible title2 w/ group?
189
+ # add an example here
157
190
  group_title, group_pos = find_group_title_and_pos!( line )
158
191
 
159
192
  pos = find_round_pos!( line )
@@ -205,15 +238,28 @@ class GameReader
205
238
  @patch_rounds[ @round.id ] = @round.id
206
239
  end
207
240
 
241
+
242
+ def try_parse_game( line )
243
+ # note: clone line; for possible test do NOT modify in place for now
244
+ # note: returns true if parsed, false if no match
245
+ parse_game( line.dup )
246
+ end
247
+
208
248
  def parse_game( line )
209
249
  logger.debug "parsing game (fixture) line: >#{line}<"
210
250
 
211
- pos = find_game_pos!( line )
212
-
213
251
  match_teams!( line )
214
252
  team1_key = find_team1!( line )
215
253
  team2_key = find_team2!( line )
216
254
 
255
+ ## note: if we do NOT find two teams; return false - no match found
256
+ if team1_key.nil? || team2_key.nil?
257
+ logger.debug " no game match (two teams required) found for line: >#{line}<"
258
+ return false
259
+ end
260
+
261
+ pos = find_game_pos!( line )
262
+
217
263
  if is_postponed?( line )
218
264
  postponed = true
219
265
  date_v2 = find_date!( line, start_at: @event.start_at )
@@ -293,21 +339,69 @@ class GameReader
293
339
  game.update_attributes!( game_attribs )
294
340
  end
295
341
 
342
+ return true # game match found
296
343
  end # method parse_game
297
344
 
298
345
 
346
+ def try_parse_date_header( line )
347
+ # note: clone line; for possible test do NOT modify in place for now
348
+ # note: returns true if parsed, false if no match
349
+ parse_date_header( line.dup )
350
+ end
351
+
352
+ def parse_date_header( line )
353
+ # note: returns true if parsed, false if no match
354
+
355
+ # line with NO teams plus include date e.g.
356
+ # [Fri Jun/17] or
357
+ # Jun/17 or
358
+ # Jun/17: etc.
359
+
360
+
361
+ match_teams!( line )
362
+ team1_key = find_team1!( line )
363
+ team2_key = find_team2!( line )
364
+
365
+ date = find_date!( line, start_at: @event.start_at )
366
+
367
+ if date.present? && team1_key.nil? && team2_key.nil?
368
+ logger.debug( "date header line found: >#{line}<")
369
+ logger.debug( " date: #{date}")
370
+ return true
371
+ else
372
+ return false
373
+ end
374
+ end
375
+
376
+
377
+
299
378
  def parse_fixtures( reader )
300
379
 
301
380
  reader.each_line do |line|
302
- if is_round?( line )
303
- parse_round( line )
304
- elsif is_group?( line ) ## NB: group goes after round (round may contain group marker too)
305
- parse_group( line )
381
+
382
+ if is_round_def?( line )
383
+ ## todo/fix: add round definition (w begin n end date)
384
+ ## todo: do not patch rounds with definition (already assume begin/end date is good)
385
+ ## -- how to deal with matches that get rescheduled/postponed?
386
+ parse_round_def( line )
387
+ elsif is_round?( line )
388
+ parse_round_header( line )
389
+ elsif is_group_def?( line ) ## NB: group goes after round (round may contain group marker too)
390
+ ### todo: add pipe (|) marker (required)
391
+ parse_group_def( line )
392
+ elsif is_group?( line )
393
+ ## -- lets you set group e.g. Group A etc.
394
+ parse_group_header( line )
395
+ elsif try_parse_game( line )
396
+ # do nothing here
397
+ elsif try_parse_date_header( line )
398
+ # do nothing here
306
399
  else
307
- parse_game( line )
400
+ logger.info "skipping line (no match found): ><"
308
401
  end
309
402
  end # lines.each
310
-
403
+
404
+
311
405
  @patch_rounds.each do |k,v|
312
406
  logger.debug "patch start_at/end_at date for round #{k}:"
313
407
  round = Round.find( k )
@@ -3,16 +3,29 @@
3
3
  module SportDb
4
4
  module FixtureHelpers
5
5
 
6
+ def is_group_def?( line )
7
+ # NB: check after is_round? (round may contain group reference!)
8
+ ## must include bar (|) marker (make required)
9
+ line =~ /\|/ && is_group?( line )
10
+ end
11
+
6
12
  def is_group?( line )
7
13
  # NB: check after is_round? (round may contain group reference!)
8
- line =~ SportDb.lang.regex_group
14
+ ## note: =~ return nil if not match found, and 0,1, etc for match
15
+ (line =~ SportDb.lang.regex_group) != nil
9
16
  end
10
17
 
11
18
  def find_group_title_and_pos!( line )
12
19
  ## group pos - for now support single digit e.g 1,2,3 or letter e.g. A,B,C or HEX
13
20
  ## nb: (?:) = is for non-capturing group(ing)
21
+
22
+ ## fix:
23
+ ## get Group|Gruppe|Grupo from lang!!!! do NOT hardcode in place
24
+
25
+ ## todo:
26
+ ## check if Group A: or [Group A] works e.g. : or ] get matched by \b ???
14
27
  regex = /(?:Group|Gruppe|Grupo)\s+((?:\d{1}|[A-Z]{1,3}))\b/
15
-
28
+
16
29
  match = regex.match( line )
17
30
 
18
31
  return [nil,nil] if match.nil?
@@ -3,8 +3,14 @@
3
3
  module SportDb
4
4
  module FixtureHelpers
5
5
 
6
+ def is_round_def?( line )
7
+ ## must include bar (|) marker (make required)
8
+ line =~ /\|/ && is_round?( line )
9
+ end
10
+
6
11
  def is_round?( line )
7
- line =~ SportDb.lang.regex_round
12
+ ## note: =~ return nil if not match found, and 0,1, etc for match
13
+ (line =~ SportDb.lang.regex_round) != nil
8
14
  end
9
15
 
10
16
  def is_knockout_round?( line )
@@ -1,6 +1,6 @@
1
1
 
2
2
  module SportDb
3
- VERSION = '1.8.9'
3
+ VERSION = '1.8.10'
4
4
  end
5
5
 
6
6
 
data/test/test_utils.rb CHANGED
@@ -10,16 +10,75 @@ require 'helper'
10
10
 
11
11
  class TestUtils < MiniTest::Unit::TestCase
12
12
 
13
+ def test_is_group_def
14
+ SportDb.lang.lang = 'en'
13
15
 
14
- class Reader
15
- include LogUtils::Logging # add logger
16
- include SportDb::FixtureHelpers
16
+ lines = [
17
+ 'Group A |',
18
+ 'Group B |'
19
+ ]
20
+
21
+ reader = Reader.new
22
+
23
+ lines.each do |line|
24
+ assert_equal true, reader.is_group_def?( line )
25
+ end
26
+ end
27
+
28
+ def test_is_group
29
+ SportDb.lang.lang = 'en'
30
+
31
+ lines = [
32
+ 'Group A',
33
+ 'Group A:',
34
+ '[Group A]'
35
+ ]
36
+
37
+ reader = Reader.new
38
+
39
+ lines.each do |line|
40
+ assert_equal true, reader.is_group?( line )
41
+ end
42
+ end
43
+
44
+
45
+ def test_is_round_def
46
+ SportDb.lang.lang = 'en'
47
+
48
+ lines = [
49
+ 'Matchday 1 |',
50
+ 'Round 1 |'
51
+ ]
52
+
53
+ reader = Reader.new
54
+
55
+ lines.each do |line|
56
+ assert_equal true, reader.is_round_def?( line )
57
+ end
58
+ end
59
+
60
+ def test_is_round
61
+ SportDb.lang.lang = 'en'
62
+
63
+ lines = [
64
+ 'Matchday 1',
65
+ '[Matchday 1]',
66
+ 'Matchday 1:',
67
+ 'Round 1'
68
+ ]
69
+
70
+ reader = Reader.new
71
+
72
+ lines.each do |line|
73
+ assert_equal true, reader.is_round?( line )
74
+ end
17
75
  end
18
76
 
77
+
19
78
  def test_is_knockout_round
20
- SportDb.lang.lang = 'en'
79
+ SportDb.lang.lang = 'en'
21
80
 
22
- lines = [
81
+ lines = [
23
82
  '(4) Quarter-finals',
24
83
  '(5) Semi-finals',
25
84
  '(6) Final'
@@ -28,7 +87,7 @@ class TestUtils < MiniTest::Unit::TestCase
28
87
  reader = Reader.new
29
88
 
30
89
  lines.each do |line|
31
- assert( reader.is_knockout_round?( line ) )
90
+ assert_equal true, reader.is_knockout_round?( line )
32
91
  end
33
92
  end
34
93
 
@@ -49,9 +108,17 @@ class TestUtils < MiniTest::Unit::TestCase
49
108
  reader = Reader.new
50
109
 
51
110
  lines.each do |line|
52
- assert( reader.is_knockout_round?( line ) )
111
+ assert_equal true, reader.is_knockout_round?( line )
53
112
  end
113
+ end
114
+
115
+ private
116
+ #######################
117
+ # private helpers
54
118
 
119
+ class Reader
120
+ include LogUtils::Logging # add logger
121
+ include SportDb::FixtureHelpers
55
122
  end
56
123
 
57
124
  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.8.9
4
+ version: 1.8.10
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: 2014-04-05 00:00:00.000000000 Z
12
+ date: 2014-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: props
16
- requirement: &83212550 !ruby/object:Gem::Requirement
16
+ requirement: &70027260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *83212550
24
+ version_requirements: *70027260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: logutils
27
- requirement: &83212160 !ruby/object:Gem::Requirement
27
+ requirement: &70026730 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *83212160
35
+ version_requirements: *70026730
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: textutils
38
- requirement: &83211780 !ruby/object:Gem::Requirement
38
+ requirement: &70026040 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *83211780
46
+ version_requirements: *70026040
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: worlddb
49
- requirement: &83211330 !ruby/object:Gem::Requirement
49
+ requirement: &70025700 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.0.2
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *83211330
57
+ version_requirements: *70025700
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: tagutils
60
- requirement: &83211060 !ruby/object:Gem::Requirement
60
+ requirement: &70025340 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *83211060
68
+ version_requirements: *70025340
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fetcher
71
- requirement: &83210570 !ruby/object:Gem::Requirement
71
+ requirement: &70025010 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0.3'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *83210570
79
+ version_requirements: *70025010
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: gli
82
- requirement: &83210080 !ruby/object:Gem::Requirement
82
+ requirement: &70024680 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 2.5.6
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *83210080
90
+ version_requirements: *70024680
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: activerecord
93
- requirement: &83209780 !ruby/object:Gem::Requirement
93
+ requirement: &70024390 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *83209780
101
+ version_requirements: *70024390
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rdoc
104
- requirement: &83209410 !ruby/object:Gem::Requirement
104
+ requirement: &70024030 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '3.10'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *83209410
112
+ version_requirements: *70024030
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: hoe
115
- requirement: &83209070 !ruby/object:Gem::Requirement
115
+ requirement: &70023610 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,7 +120,7 @@ dependencies:
120
120
  version: '3.3'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *83209070
123
+ version_requirements: *70023610
124
124
  description: sportdb - sport.db command line tool
125
125
  email: opensport@googlegroups.com
126
126
  executables: