icu_tournament 1.9.5 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 74df6f6b05bbaf0a54ce055e247c4ece9e64ec16
4
- data.tar.gz: 427004e7f6b7fab5a6b632fd3b4ea38a21ffcdfe
2
+ SHA256:
3
+ metadata.gz: c9f5ebb60437a28fd66022167c933153271bcd138c47503b3a6082f8ffb2c235
4
+ data.tar.gz: e59666cca208d270d61b787625c356779003c289836bb613ecfa63542a12ff6f
5
5
  SHA512:
6
- metadata.gz: 027f715f83f6eeab51c8aeab5d42b9bacd004cebcd8557c8f0792c160c1ebc4ed55641d670ea41173e8dacaf19ca1e53d32546a0f07048661e71281ddc3732d5
7
- data.tar.gz: eb3fe4ae2559df38e4a127aa571e0956833626bea49f0dda5a59cde0ad625c29e433e3a2b48139f75a9ab675d79cbb2db88b0a5df07f9225f04d0c5418fb66ea
6
+ metadata.gz: 53991697d9454d160f34b4e30139f08965af76ed53833b671a15a927f829707fed16242dca1640acb878e7a6c90311fb43c985a4395776e37a38d7acd0cf083d
7
+ data.tar.gz: b580e1fd42864b5fbc363a33f0efa44c380e05cba236d308b7d968663b04d1c81bd97fb847a300e71db154e3f5ae872f4b2c5654ebf4e455d65b7262adc873c7
data/README.rdoc CHANGED
@@ -4,7 +4,7 @@ For reading or writing files of chess tournament data. Original project name on
4
4
 
5
5
  == Install
6
6
 
7
- For Ruby 1.9.2, 1.9.3, 2.0.0 (version 1.1.2 was the last compatible with Ruby 1.8.7).
7
+ For Ruby 1.9.2, 1.9.3, 2.0.0, 2.2.1 (version 1.1.2 was the last compatible with Ruby 1.8.7).
8
8
 
9
9
  gem install icu_tournament
10
10
 
@@ -74,3 +74,7 @@ On error, the _parse_ method returns _nil_ and an error message can be retrieved
74
74
  == Author
75
75
 
76
76
  Mark Orr, rating officer for the Irish Chess Union (ICU[http://icu.ie]).
77
+
78
+ == Current Maintainer
79
+
80
+ David Murray, rating officer for the Irish Chess Union. Contact ratings@icu.ie.
@@ -119,7 +119,6 @@ module ICU
119
119
  # Canonicalise and set the first name(s).
120
120
  def first_name=(first_name)
121
121
  name = Name.new(first_name, 'Last')
122
- raise "invalid first name" unless name.first.length > 0
123
122
  @first_name = name.first
124
123
  end
125
124
 
@@ -154,6 +153,7 @@ module ICU
154
153
  @title << 'M' if @title.match(/[A-LN-Z]$/)
155
154
  @title = 'IM' if @title == 'M'
156
155
  @title = 'WIM' if @title == 'WM'
156
+ @title = '' if @title.match(/^(AFM|AIM|AGM)$/)
157
157
  @title = nil if @title == ''
158
158
  raise "invalid chess title (#{title})" unless @title.nil? || @title.match(/^W?[GIFCN]M$/)
159
159
  end
@@ -235,4 +235,4 @@ module ICU
235
235
  end
236
236
  end
237
237
  end
238
- end
238
+ end
@@ -129,7 +129,7 @@ module ICU
129
129
  def opponent=(opponent)
130
130
  @opponent = case opponent
131
131
  when nil then nil
132
- when Fixnum then opponent
132
+ when Integer then opponent
133
133
  when /^\s*$/ then nil
134
134
  else opponent.to_i
135
135
  end
@@ -198,4 +198,4 @@ module ICU
198
198
  true
199
199
  end
200
200
  end
201
- end
201
+ end
@@ -379,6 +379,44 @@ module ICU
379
379
  self
380
380
  end
381
381
 
382
+ # Make an educated guess at round dates.
383
+ # If only one round, it is on the start date
384
+ # If start and end date match, all rounds are on that day
385
+ # If there are exactly two rounds, round 1 on the start day, round 2 on the finish day
386
+ # If there are between n and 2n rounds in n consecutive days, then
387
+ # start with one round a day, switch to two rounds a day when that's needed
388
+ # If there are 7 rounds Saturday - Sunday > 1 week: two on the first 3 weekend dates, one on the final Sunday
389
+ # This covers most Irish tournaments. Returns an empty array if it could not guess
390
+ def guess_round_dates
391
+ return [@start] if rounds == 1
392
+ return [] if @finish.nil?
393
+
394
+ round_dates = []
395
+ start_date = ::Date.parse(@start)
396
+ finish_date = ::Date.parse(@finish)
397
+ ndays = (finish_date - start_date).to_i + 1
398
+ if ndays == 1
399
+ rounds.times { round_dates << start }
400
+ elsif rounds == 2
401
+ round_dates << start
402
+ round_dates << finish
403
+ elsif ndays <= rounds and rounds <= ndays * 2
404
+ double_rounds = rounds - ndays
405
+ (0...ndays).each do |r|
406
+ round_dates << start_date + r
407
+ if r >= (ndays - double_rounds)
408
+ round_dates << start_date + r
409
+ end
410
+ end
411
+ elsif rounds == 7 and start_date.wday == 6 and finish_date.wday == 0 and ndays > 7
412
+ 2.times { round_dates << start_date }
413
+ 2.times { round_dates << start_date + 1 }
414
+ 2.times { round_dates << finish_date - 1 }
415
+ round_dates << finish_date
416
+ end
417
+ return round_dates
418
+ end
419
+
382
420
  # Is a tournament invalid? Either returns false (if it's valid) or an error message.
383
421
  # Has the same _rerank_ option as validate!.
384
422
  def invalid(options={})
@@ -336,7 +336,7 @@ module ICU
336
336
  if old_player.id
337
337
  old_player.merge(opponent)
338
338
  old_result = @player.find_result(@round)
339
- raise "missing result for player (#{@player.name}) in round #{@round}" unless old_result
339
+ raise "result for player (#{@player.name}) in round #{@round} does not match previous result for opponent (#{old_player.name})" unless old_result
340
340
  raise "mismatched results for player (#{old_player.name}): #{result.inspect} #{old_result.inspect}" unless result.eql?(old_result)
341
341
  else
342
342
  old_result = old_player.find_result(@round)
@@ -326,9 +326,13 @@ module ICU
326
326
  krause << "\n"
327
327
  end
328
328
  rounds = t.last_round
329
- if t.round_dates.size == rounds && rounds > 0
329
+ round_dates = t.round_dates
330
+ if round_dates.empty?
331
+ round_dates = t.guess_round_dates.map { |d| d.to_s }
332
+ end
333
+ if round_dates.size == rounds && rounds > 0
330
334
  krause << "132 #{' ' * 85}"
331
- t.round_dates.each{ |d| krause << d.sub(/^../, ' ') }
335
+ round_dates.each{ |d| krause << d.sub(/^../, ' ') }
332
336
  krause << "\n"
333
337
  end
334
338
  t.players.each{ |p| krause << p.to_krause(rounds, arg) }
@@ -433,11 +437,18 @@ module ICU
433
437
  full_byes << round
434
438
  return 0.0
435
439
  end
436
- data = "#{data} -" if data.match(/^\d+ (w|b|-)$/)
437
- raise "invalid result '#{data}'" unless data.match(/^(0{1,4}|[1-9]\d{0,3}) (w|b|-) (1|0|=|\+|-)$/)
438
- opponent = $1.to_i
439
- colour = $2
440
- score = $3
440
+ data = "#{data} -" if data.match(/^(\d+)? (w|b|-)$/)
441
+ if data.match(/^(0{1,4}|[1-9]\d{0,3}) (w|b|-) (1|0|=|\+|-)$/)
442
+ opponent = $1.to_i
443
+ colour = $2
444
+ score = $3
445
+ elsif data.match(/- (1|0|=|\+|-)$/)
446
+ opponent = 0
447
+ colour = "-"
448
+ score = $1
449
+ else
450
+ raise "invalid result '#{data}'"
451
+ end
441
452
  options = Hash.new
442
453
  options[:opponent] = opponent unless opponent == 0
443
454
  options[:colour] = colour unless colour == '-'
@@ -459,7 +470,7 @@ module ICU
459
470
  return false unless total <= sum + full_byes.size * 1.0 + half_byes.size * 0.5
460
471
  full_byes.each_index do |i|
461
472
  bye = full_byes[i]
462
- if bye.class == Fixnum
473
+ if bye.class == Integer
463
474
  # Round number - create a half-point bye in that round.
464
475
  result = Result.new(bye, player, '=')
465
476
  @results << ['none', player, "extra bye for player #{player} in round #{bye}", result]
@@ -72,7 +72,7 @@ module ICU
72
72
  names.each do |name|
73
73
  attr_accessor(name) do |val|
74
74
  tmp = val.to_i
75
- raise "invalid integer (#{val}) for #{name}" unless val.is_a?(Fixnum) || (val.is_a?(::String) && val.include?(tmp.to_s))
75
+ raise "invalid integer (#{val}) for #{name}" unless val.is_a?(Integer) || (val.is_a?(::String) && val.include?(tmp.to_s))
76
76
  tmp
77
77
  end
78
78
  end
@@ -83,7 +83,7 @@ module ICU
83
83
  attr_accessor(name) do |val|
84
84
  tmp = case val
85
85
  when nil then nil
86
- when Fixnum then val
86
+ when Integer then val
87
87
  when /^\s*$/ then nil
88
88
  else val.to_i
89
89
  end
@@ -108,7 +108,7 @@ module ICU
108
108
  attr_accessor(name) do |val|
109
109
  tmp = case val
110
110
  when nil then nil
111
- when Fixnum then val
111
+ when Integer then val
112
112
  when /^\s*$/ then nil
113
113
  else val.to_i
114
114
  end
@@ -166,4 +166,4 @@ module ICU
166
166
  end
167
167
  end
168
168
  end
169
- end
169
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ICU
4
4
  class Tournament
5
- VERSION = "1.9.5"
5
+ VERSION = "1.11.0"
6
6
  end
7
7
  end
data/spec/player_spec.rb CHANGED
@@ -31,13 +31,11 @@ module ICU
31
31
  end
32
32
 
33
33
  it "should not contain invalid characters" do
34
- expect { Player.new('12', 'Orr', 1) }.to raise_error(/invalid first name/)
35
34
  expect { Player.new('Mark', '*!', 1) }.to raise_error(/invalid last name/)
36
35
  end
37
36
 
38
- it "should not have empty last name or first name" do
37
+ it "should not have empty last name" do
39
38
  expect { Player.new('Mark', '', 1) }.to raise_error(/invalid last name/)
40
- expect { Player.new('', 'Orr', 1) }.to raise_error(/invalid first name/)
41
39
  end
42
40
 
43
41
  it "both names can be returned together" do
@@ -135,6 +133,10 @@ module ICU
135
133
  expect(Player.new('Eamon', 'Keogh', 6, :title => 'nm').title).to eq('NM')
136
134
  expect { Player.new('Mark', 'Orr', 3, :title => 'Dr') }.to raise_error(/invalid chess title/)
137
135
  end
136
+
137
+ it "should ignore Arena titles" do
138
+ expect(Player.new('Darko', 'Polimac', 3, :title => 'AGM').title).to be_nil
139
+ end
138
140
  end
139
141
 
140
142
  context "rating" do
@@ -371,4 +373,4 @@ module ICU
371
373
  end
372
374
  end
373
375
  end
374
- end
376
+ end
@@ -299,6 +299,10 @@ REORDERED
299
299
 
300
300
  context "serialisation of a manually built tournament" do
301
301
  before(:all) do
302
+ @dates = <<DATES
303
+ 132 08-06-07 08-06-08 08-06-09
304
+ DATES
305
+ @dates.strip!
302
306
  @krause = <<KRAUSE
303
307
  012 Las Vegas National Open
304
308
  042 2008-06-07
@@ -321,6 +325,15 @@ KRAUSE
321
325
  it "should serialise" do
322
326
  expect(@output).to eq(@krause)
323
327
  end
328
+
329
+ it "should add round dates" do
330
+ @t.rounds = 3
331
+ @t.finish = ::Date.parse('2008-06-09')
332
+ output = @p.serialize(@t)
333
+ expect(output).not_to eq(@krause)
334
+ expect(output).to match(@dates)
335
+ end
336
+
324
337
  end
325
338
 
326
339
  context "customised serialisation with ICU IDs" do
@@ -807,6 +820,12 @@ KRAUSE
807
820
  expect { @p.parse_file!(file) }.not_to raise_error
808
821
  end
809
822
 
823
+ it "should handle Cork Major 2018 (Swiss Master format)" do
824
+ file = "#{@s}/cork_major_2018_swissmaster.tab"
825
+ @t = @p.parse_file(file, :fed => :ignore)
826
+ check_results(1, 6, 3.5)
827
+ end
828
+
810
829
  it "should handle a file with a BOM" do
811
830
  file = "#{@s}/armstrong_2012_with_bom.tab"
812
831
  expect { @p.parse_file!(file) }.not_to raise_error
@@ -210,6 +210,53 @@ EOS
210
210
  end
211
211
  end
212
212
 
213
+ context "guess round date" do
214
+ before(:each) do
215
+ @ennis = Tournament.new('Ennis Shield Round 1', '2019-09-24', :rounds => 1)
216
+ @u12 = Tournament.new('Leinster U12', '2019-01-05', :finish => '2019-01-05', :rounds => 4)
217
+ @armstrong = Tournament.new('Armstrong Cup Rounds 1-2', '2019-09-28', :finish => '2019-10-14', :rounds => 2)
218
+ @irish = Tournament.new('Irish Championship', '2019-08-03', :finish => '2019-08-11', :rounds => 9)
219
+ @malahide = Tournament.new('Malahide Millenium', '2019-05-04', :finish => '2019-05-06', :rounds => 6)
220
+ @gonzaga = Tournament.new('Gonzaga Classic', '2019-01-25', :finish => '2019-01-27', :rounds => 5)
221
+ @sona = Tournament.new('Sona Super Cup U14', '2018-10-20', :finish => '2018-11-25', :rounds => 7)
222
+ end
223
+
224
+ it "should get one round date when only one round" do
225
+ guess = @ennis.guess_round_dates
226
+ expect(guess.join('|')).to eq('2019-09-24')
227
+ end
228
+
229
+ it "should get all rounds on right day when only one day" do
230
+ guess = @u12.guess_round_dates
231
+ expect(guess.join('|')).to eq('2019-01-05|2019-01-05|2019-01-05|2019-01-05')
232
+ end
233
+
234
+ it "two rounds" do
235
+ guess = @armstrong.guess_round_dates
236
+ expect(guess.join('|')).to eq('2019-09-28|2019-10-14')
237
+ end
238
+
239
+ it "9 rounds in 9 days" do
240
+ guess = @irish.guess_round_dates
241
+ expect(guess.join('|')).to eq('2019-08-03|2019-08-04|2019-08-05|2019-08-06|2019-08-07|2019-08-08|2019-08-09|2019-08-10|2019-08-11')
242
+ end
243
+
244
+ it "6 rounds in 3 days" do
245
+ guess = @malahide.guess_round_dates
246
+ expect(guess.join('|')).to eq('2019-05-04|2019-05-04|2019-05-05|2019-05-05|2019-05-06|2019-05-06')
247
+ end
248
+
249
+ it "5 rounds in 3 days" do
250
+ guess = @gonzaga.guess_round_dates
251
+ expect(guess.join('|')).to eq('2019-01-25|2019-01-26|2019-01-26|2019-01-27|2019-01-27')
252
+ end
253
+
254
+ it "7 rounds in 2 weekends" do
255
+ guess = @sona.guess_round_dates
256
+ expect(guess.join('|')).to eq('2018-10-20|2018-10-20|2018-10-21|2018-10-21|2018-11-24|2018-11-24|2018-11-25')
257
+ end
258
+ end
259
+
213
260
  context "site" do
214
261
  it "defaults to nil" do
215
262
  expect(Tournament.new('Edinburgh Masters', '2009-11-09').site).to be_nil
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icu_tournament
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.5
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Orr
8
+ - David Murray
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-03-07 00:00:00.000000000 Z
12
+ date: 2021-08-10 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: dbf
@@ -58,14 +59,20 @@ dependencies:
58
59
  requirements:
59
60
  - - "~>"
60
61
  - !ruby/object:Gem::Version
61
- version: '1.2'
62
+ version: '1.3'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 1.3.2
62
66
  type: :runtime
63
67
  prerelease: false
64
68
  version_requirements: !ruby/object:Gem::Requirement
65
69
  requirements:
66
70
  - - "~>"
67
71
  - !ruby/object:Gem::Version
68
- version: '1.2'
72
+ version: '1.3'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.3.2
69
76
  - !ruby/object:Gem::Dependency
70
77
  name: bundler
71
78
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +131,7 @@ dependencies:
124
131
  version: '4.2'
125
132
  description: Convert files of chess tournament data in different formats to ruby classes
126
133
  and vice-versa.
127
- email: mark.j.l.orr@googlemail.com
134
+ email: davidmurray11@gmail.com
128
135
  executables: []
129
136
  extensions: []
130
137
  extra_rdoc_files:
@@ -156,7 +163,7 @@ files:
156
163
  - spec/tournament_spec.rb
157
164
  - spec/tournament_spx_spec.rb
158
165
  - spec/util_spec.rb
159
- homepage: http://github.com/sanichi/icu_tournament
166
+ homepage: http://github.com/dbtmurray/icu_tournament
160
167
  licenses:
161
168
  - MIT
162
169
  metadata: {}
@@ -168,27 +175,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
175
  requirements:
169
176
  - - ">="
170
177
  - !ruby/object:Gem::Version
171
- version: '0'
178
+ version: '2.4'
172
179
  required_rubygems_version: !ruby/object:Gem::Requirement
173
180
  requirements:
174
181
  - - ">="
175
182
  - !ruby/object:Gem::Version
176
183
  version: '0'
177
184
  requirements: []
178
- rubyforge_project: icu_tournament
179
- rubygems_version: 2.4.5
185
+ rubygems_version: 3.0.1
180
186
  signing_key:
181
187
  specification_version: 4
182
188
  summary: For reading and writing files of chess tournament data.
183
189
  test_files:
184
- - spec/player_spec.rb
185
- - spec/result_spec.rb
186
- - spec/spec_helper.rb
187
190
  - spec/team_spec.rb
188
- - spec/tie_break_spec.rb
189
- - spec/tournament_fcsv_spec.rb
190
- - spec/tournament_krause_spec.rb
191
- - spec/tournament_sp_spec.rb
191
+ - spec/player_spec.rb
192
192
  - spec/tournament_spec.rb
193
+ - spec/tournament_fcsv_spec.rb
194
+ - spec/tie_break_spec.rb
193
195
  - spec/tournament_spx_spec.rb
196
+ - spec/result_spec.rb
194
197
  - spec/util_spec.rb
198
+ - spec/spec_helper.rb
199
+ - spec/tournament_sp_spec.rb
200
+ - spec/tournament_krause_spec.rb