icu_tournament 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -73,6 +73,20 @@ module ICU
73
73
  #
74
74
  # See ICU::Player and ICU::Result for more details about players and results.
75
75
  #
76
+ # == Tournament Dates
77
+ #
78
+ # A tournament start date is mandatory and supplied in the constructor. Finish and round dates are optional.
79
+ # To supply a finish date, supply it in constructor arguments or set it explicityly.
80
+ #
81
+ # t = ICU::Tournament.new('Bangor Masters', '2009-11-09', :finish => '2009-11-11')
82
+ # t.finish = '2009-11-11'
83
+ #
84
+ # To set round dates, add the correct number in the correct order one at a time.
85
+ #
86
+ # t.add_round_date('2009-11-09')
87
+ # t.add_round_date('2009-11-10')
88
+ # t.add_round_date('2009-11-11')
89
+ #
76
90
  # == Validation
77
91
  #
78
92
  # A tournament can be validated with either the <em>validate!</em> or _invalid_ methods.
@@ -213,7 +227,6 @@ module ICU
213
227
  parsed_date = Util.parsedate(round_date)
214
228
  raise "invalid round date (#{round_date})" unless parsed_date
215
229
  @round_dates << parsed_date
216
- @round_dates.sort!
217
230
  end
218
231
 
219
232
  # Return the date of a given round, or nil if unavailable.
@@ -472,8 +485,12 @@ module ICU
472
485
  raise "start date (#{start}) is after end date (#{finish})" if @start && @finish && @start > @finish
473
486
  if @round_dates.size > 0
474
487
  raise "the number of round dates (#{@round_dates.size}) does not match the number of rounds (#{@rounds})" unless @round_dates.size == @rounds
475
- raise "the date of the first round (#{@round_dates[0]}) comes before the start (#{@start}) of the tournament" if @start && @start > @round_dates[0]
476
- raise "the date of the last round (#{@round_dates[-1]}) comes after the end (#{@finish}) of the tournament" if @finish && @finish < @round_dates[-1]
488
+ raise "the date of the first round (#{@round_dates[0]}) does not match the start (#{@start}) of the tournament" if @start && @start != @round_dates[0]
489
+ raise "the date of the last round (#{@round_dates[-1]}) does not match the end (#{@finish}) of the tournament" if @finish && @finish != @round_dates[-1]
490
+ (2..@round_dates.size).to_a.each do |r|
491
+ #puts "#{@round_dates[r-2]} => #{@round_dates[r-1]}"
492
+ raise "the date of round #{r-1} (#{@round_dates[r-2]}) is after the date of round #{r} (#{@round_dates[r-1]}) of the tournament" if @round_dates[r-2] > @round_dates[r-1]
493
+ end
477
494
  @finish = @round_dates[-1] unless @finish
478
495
  end
479
496
  end
@@ -251,7 +251,7 @@ module ICU
251
251
  when '102' then @tournament.arbiter = @data # arbiter(s)
252
252
  when '112' then @tournament.deputy = @data # deputy(ies)
253
253
  when '122' then @tournament.time_control = @data # time control
254
- when '132' then add_round_dates # round dates
254
+ when '132' then add_round_dates(arg) # round dates
255
255
  else raise "invalid DIN #{din}"
256
256
  end
257
257
  rescue => err
@@ -372,7 +372,7 @@ module ICU
372
372
  lines
373
373
  end
374
374
 
375
- def add_player(arg={})
375
+ def add_player(arg)
376
376
  raise "player record less than minimum length" if @line.length < 99
377
377
 
378
378
  # Prepare player details.
@@ -491,7 +491,8 @@ module ICU
491
491
  @tournament.add_team(team)
492
492
  end
493
493
 
494
- def add_round_dates
494
+ def add_round_dates(arg)
495
+ return if arg[:round_dates].to_s == 'ignore'
495
496
  raise "round dates record less than minimum length" if @line.length < 99
496
497
  index = 87
497
498
  american = nil
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ICU
4
4
  class Tournament
5
- VERSION = "1.5.4"
5
+ VERSION = "1.5.5"
6
6
  end
7
7
  end
@@ -176,7 +176,7 @@ KRAUSE
176
176
  022 Las Vegas
177
177
  032 USA
178
178
  042 2008-06-07
179
- 052 2008-06-10
179
+ 052 2008-06-09
180
180
  092 All-Play-All
181
181
  102 Hans Scmidt
182
182
  112 Gerry Graham, Herbert Scarry
@@ -297,7 +297,7 @@ REORDERED
297
297
  end
298
298
  end
299
299
 
300
- context "serialisation of a manually build tournament" do
300
+ context "serialisation of a manually built tournament" do
301
301
  before(:all) do
302
302
  @krause = <<KRAUSE
303
303
  012 Las Vegas National Open
@@ -453,12 +453,13 @@ KRAUSE
453
453
  012 Gonzaga Classic
454
454
  022 Dublin
455
455
  032 IRL
456
- 042 2008-02-01
457
- 052 2008-02-03
456
+ 042 2008-02-21
457
+ 052 2008-02-25
458
458
  062 12
459
459
  092 Swiss
460
460
  102 Michael Germaine, mlgermaine@eircom.net
461
461
  122 120 minutes per player per game
462
+ 132 08.02.21 08.02.22 08.02.23 08.02.24 08.02.25
462
463
  001 1 Griffiths,Ryan Rhys IRL 2502054 1993-12-20 4.0 1 0000 - = 3 b 1 8 w 1 5 b = 7 w 1
463
464
  001 2 Hotak,Marian SVK 14909677 3.5 2 3 w 0 6 b = 11 w 1 8 b 1 5 w 1
464
465
  001 3 Duffy,Seamus IRL 3.0 3 2 b 1 1 w 0 4 w 1 6 b = 8 w =
@@ -480,8 +481,7 @@ KRAUSE
480
481
  end
481
482
 
482
483
  it "removing the line on which the tournament name is specified should cause an error" do
483
- @k.sub!('012 Gonzaga Classic', '')
484
- lambda { @p.parse!(@k) }.should raise_error(/name missing/)
484
+ lambda { @p.parse!(@k.sub('012 Gonzaga Classic', '')) }.should raise_error(/name missing/)
485
485
  end
486
486
 
487
487
  it "blanking the tournament name should cause an error" do
@@ -489,45 +489,53 @@ KRAUSE
489
489
  lambda { @p.parse!(@k) }.should raise_error(/name missing/)
490
490
  end
491
491
 
492
+ it "the start cannot be later than the end date" do
493
+ lambda { @p.parse!(@k.sub('2008-02-21', '2008-03-21')) }.should raise_error(/start.*after.*end/)
494
+ end
495
+
492
496
  it "blanking the start date should cause an error" do
493
- @k.sub!('2008-02-01', '2008-02-04')
494
- lambda { @p.parse!(@k) }.should raise_error(/start.*after.*end/)
497
+ lambda { @p.parse!(@k.sub('2008-02-21', '')) }.should raise_error(/start date missing/)
495
498
  end
496
499
 
497
- it "the start cannot be later than the end date" do
498
- @k.sub!('2008-02-01', '')
499
- lambda { @p.parse!(@k) }.should raise_error(/start date missing/)
500
+ it "the first and last round dates should match the tournament start and end dates" do
501
+ lambda { @p.parse!(@k.sub('08.02.21', '08.02.20')) }.should raise_error(/first round.*not match.*start/)
502
+ lambda { @p.parse!(@k.sub('08.02.21', '08.02.22')) }.should raise_error(/first round.*not match.*start/)
503
+ lambda { @p.parse!(@k.sub('08.02.25', '08.02.24')) }.should raise_error(/last round.*not match.*end/)
504
+ lambda { @p.parse!(@k.sub('08.02.25', '08.02.26')) }.should raise_error(/last round.*not match.*end/)
505
+ end
506
+
507
+ it "the round dates should never decrease" do
508
+ lambda { @p.parse!(@k.sub('08.02.24', '08.02.22')) }.should raise_error(/round 3.*after.*round 4/)
509
+ end
510
+
511
+ it "bad round dates can be ignored" do
512
+ lambda { @p.parse!(@k.sub('08.02.21', '08.02.20'), :round_dates => "ignore") }.should_not raise_error
513
+ lambda { @p.parse!(@k.sub('08.02.24', '08.02.22'), :round_dates => "ignore") }.should_not raise_error
500
514
  end
501
515
 
502
516
  it "creating a duplicate player number should cause an error" do
503
- @k.sub!(' 2 ', ' 1 ')
504
- lambda { @p.parse!(@k) }.should raise_error(/player number/)
517
+ lambda { @p.parse!(@k.sub(' 2 ', ' 1 ')) }.should raise_error(/player number/)
505
518
  end
506
519
 
507
520
  it "creating a duplicate rank number should not cause an error becuse the tournament will be reranked" do
508
- @k.sub!('4.0 1', '4.0 2')
509
- t = @p.parse!(@k)
521
+ t = @p.parse!(@k.sub('4.0 1', '4.0 2'))
510
522
  t.player(1).rank.should == 1
511
523
  end
512
524
 
513
525
  it "referring to a non-existant player number should cause an error" do
514
- @k.sub!(' 3 b 1', '33 b 1')
515
- lambda { @p.parse!(@k) }.should raise_error(/opponent number/)
526
+ lambda { @p.parse!(@k.sub(' 3 b 1', '33 b 1')) }.should raise_error(/opponent number/)
516
527
  end
517
528
 
518
529
  it "inconsistent colours should cause an error" do
519
- @k.sub!('3 b 1', '3 w 1')
520
- lambda { @p.parse!(@k) }.should raise_error(/result/)
530
+ lambda { @p.parse!(@k.sub('3 b 1', '3 w 1')) }.should raise_error(/result/)
521
531
  end
522
532
 
523
533
  it "inconsistent scores should cause an error" do
524
- @k.sub!('3 b 1', '3 b =')
525
- lambda { @p.parse!(@k) }.should raise_error(/result/)
534
+ lambda { @p.parse!(@k.sub('3 b 1', '3 b =')) }.should raise_error(/result/)
526
535
  end
527
536
 
528
537
  it "inconsistent totals should cause an error" do
529
- @k.sub!('3.5', '4.0')
530
- lambda { @p.parse!(@k) }.should raise_error(/total/)
538
+ lambda { @p.parse!(@k.sub('3.5', '4.0')) }.should raise_error(/total/)
531
539
  end
532
540
 
533
541
  it "invalid federations should cause an error unless an option is used" do
@@ -542,14 +550,12 @@ KRAUSE
542
550
  end
543
551
 
544
552
  it "an invalid DOB is silently ignored" do
545
- @k.sub!(/1993-12-20/, '1993 ')
546
- lambda { @t = @p.parse!(@k) }.should_not raise_error
553
+ lambda { @t = @p.parse!(@k.sub(/1993-12-20/, '1993 ')) }.should_not raise_error
547
554
  @t.player(1).dob.should be_nil
548
555
  end
549
556
 
550
557
  it "removing any player that somebody else has played should cause an error" do
551
- @k.sub!(/^001 12.*$/, '')
552
- lambda { @p.parse!(@k) }.should raise_error(/opponent/)
558
+ lambda { @p.parse!(@k.sub(/^001 12.*$/, '')) }.should raise_error(/opponent/)
553
559
  end
554
560
  end
555
561
 
@@ -202,10 +202,10 @@ EOS
202
202
  @t.round_dates.size.should == 0
203
203
  end
204
204
 
205
- it "can be added one by one in any order" do
206
- @t.add_round_date('2009-11-11')
205
+ it "should be added one by one in the correct order" do
207
206
  @t.add_round_date('09/11/2009')
208
207
  @t.add_round_date('10th November 2009')
208
+ @t.add_round_date('2009-11-11')
209
209
  @t.round_dates.join('|').should == '2009-11-09|2009-11-10|2009-11-11'
210
210
  end
211
211
  end
@@ -428,12 +428,12 @@ EOS
428
428
 
429
429
  it "should detect an inconsistent start date" do
430
430
  @t.start = '2009-11-10'
431
- lambda { @t.validate! }.should raise_error(/first round.*before.*start/)
431
+ lambda { @t.validate! }.should raise_error(/first round.*not match.*start/)
432
432
  end
433
433
 
434
434
  it "should detect an inconsistent finish date" do
435
435
  @t.finish = '2009-11-10'
436
- lambda { @t.validate! }.should raise_error(/last round.*after.*end/)
436
+ lambda { @t.validate! }.should raise_error(/last round.*not match.*end/)
437
437
  end
438
438
 
439
439
  it "should have side effect of setting missing finish date" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icu_tournament
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.4
4
+ version: 1.5.5
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: 2011-10-01 00:00:00.000000000Z
12
+ date: 2011-10-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dbf
16
- requirement: &70190448724460 !ruby/object:Gem::Requirement
16
+ requirement: &70266168398620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.2.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70190448724460
24
+ version_requirements: *70266168398620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rubyzip
27
- requirement: &70190448703880 !ruby/object:Gem::Requirement
27
+ requirement: &70266168397220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.9.4
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70190448703880
35
+ version_requirements: *70266168397220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: icu_name
38
- requirement: &70190448702960 !ruby/object:Gem::Requirement
38
+ requirement: &70266168331460 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70190448702960
46
+ version_requirements: *70266168331460
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &70190448702120 !ruby/object:Gem::Requirement
49
+ requirement: &70266168330560 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70190448702120
57
+ version_requirements: *70266168330560
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &70190448701400 !ruby/object:Gem::Requirement
60
+ requirement: &70266168329420 !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: :development
67
67
  prerelease: false
68
- version_requirements: *70190448701400
68
+ version_requirements: *70266168329420
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &70190448700540 !ruby/object:Gem::Requirement
71
+ requirement: &70266168328480 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70190448700540
79
+ version_requirements: *70266168328480
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard-rspec
82
- requirement: &70190448699360 !ruby/object:Gem::Requirement
82
+ requirement: &70266168327280 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70190448699360
90
+ version_requirements: *70266168327280
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rdoc
93
- requirement: &70190448698680 !ruby/object:Gem::Requirement
93
+ requirement: &70266168325800 !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: :development
100
100
  prerelease: false
101
- version_requirements: *70190448698680
101
+ version_requirements: *70266168325800
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rb-fsevent
104
- requirement: &70190448697860 !ruby/object:Gem::Requirement
104
+ requirement: &70266168324640 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70190448697860
112
+ version_requirements: *70266168324640
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: growl
115
- requirement: &70190448696860 !ruby/object:Gem::Requirement
115
+ requirement: &70266165709760 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,7 +120,7 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70190448696860
123
+ version_requirements: *70266165709760
124
124
  description: Convert files of chess tournament data in different formats to ruby classes
125
125
  and vice-versa.
126
126
  email: mark.j.l.orr@googlemail.com
@@ -171,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
171
  version: '0'
172
172
  segments:
173
173
  - 0
174
- hash: 1118276685210611974
174
+ hash: 2742287877822509535
175
175
  required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  none: false
177
177
  requirements:
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  version: '0'
181
181
  segments:
182
182
  - 0
183
- hash: 1118276685210611974
183
+ hash: 2742287877822509535
184
184
  requirements: []
185
185
  rubyforge_project: icu_tournament
186
186
  rubygems_version: 1.8.6