icu_tournament 1.9.7 → 1.9.8

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
2
  SHA256:
3
- metadata.gz: e1f1c6f7bc5da88c02ef93bb645ea1c66a74a524c9660228b113a9534dda9fe1
4
- data.tar.gz: 2aabe2659d391ce17af265bc90bbad37e23b358eb869f2223fa84b8cf33f6ec3
3
+ metadata.gz: 10ccb760bf0c8acf97cdd786e8a5f3f42c97604094b95b011890fca5a53c6c21
4
+ data.tar.gz: 29fc8cf00fc3e950bb36a36e26f5ed9ce1c6f23960b35d05172a0ef2597ce579
5
5
  SHA512:
6
- metadata.gz: cb4e37782391a243362b0852538dd032f5c6a291ea0e404ffa110e28ed2df3593d182a35628f70a3044e915a5ff303959fdf4d344c6e9ebb3066bf9b6640b846
7
- data.tar.gz: 932cf6f1d651cda6edf1d7fb93f6dc999be911e2009bcdd7c816ff9dde9ba48f3b80197fdaed81d1a960a7284a4f619e46d379da2e8d30763d107dbe9dd3f36d
6
+ metadata.gz: 6adf8f1414bbf4514c2cf441964381b5fa7e40397b6ac7ff0e710f158788ae4ff3fc66ebf1dac79f269f797cfb2fe389dedae9c8be06ab2ceb47ba4de11b1ff0
7
+ data.tar.gz: d2127da4cb39dc6d8bdf18b4832b35dfbf285e0d203d0ec2c0ea162f95c25ddb397dff3db66ba852279642c7ff8da478acd15e664dd44da36a31632ae2673b30
@@ -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
 
@@ -235,4 +234,4 @@ module ICU
235
234
  end
236
235
  end
237
236
  end
238
- end
237
+ 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) }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ICU
4
4
  class Tournament
5
- VERSION = "1.9.7"
5
+ VERSION = "1.9.8"
6
6
  end
7
7
  end
@@ -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
@@ -371,4 +369,4 @@ module ICU
371
369
  end
372
370
  end
373
371
  end
374
- end
372
+ 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
@@ -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.7
4
+ version: 1.9.8
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: 2019-02-03 00:00:00.000000000 Z
12
+ date: 2019-11-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: dbf
@@ -124,7 +125,7 @@ dependencies:
124
125
  version: '4.2'
125
126
  description: Convert files of chess tournament data in different formats to ruby classes
126
127
  and vice-versa.
127
- email: mark.j.l.orr@googlemail.com
128
+ email: davidmurray11@gmail.com
128
129
  executables: []
129
130
  extensions: []
130
131
  extra_rdoc_files:
@@ -156,7 +157,7 @@ files:
156
157
  - spec/tournament_spec.rb
157
158
  - spec/tournament_spx_spec.rb
158
159
  - spec/util_spec.rb
159
- homepage: http://github.com/sanichi/icu_tournament
160
+ homepage: http://github.com/dbtmurray/icu_tournament
160
161
  licenses:
161
162
  - MIT
162
163
  metadata: {}
@@ -181,14 +182,14 @@ signing_key:
181
182
  specification_version: 4
182
183
  summary: For reading and writing files of chess tournament data.
183
184
  test_files:
184
- - spec/result_spec.rb
185
- - spec/tournament_fcsv_spec.rb
186
185
  - spec/team_spec.rb
187
- - spec/util_spec.rb
188
186
  - spec/player_spec.rb
189
187
  - spec/tournament_spec.rb
190
- - spec/tournament_krause_spec.rb
191
- - spec/tournament_sp_spec.rb
188
+ - spec/tournament_fcsv_spec.rb
192
189
  - spec/tie_break_spec.rb
193
- - spec/spec_helper.rb
194
190
  - spec/tournament_spx_spec.rb
191
+ - spec/result_spec.rb
192
+ - spec/util_spec.rb
193
+ - spec/spec_helper.rb
194
+ - spec/tournament_sp_spec.rb
195
+ - spec/tournament_krause_spec.rb