icu_tournament 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,17 +15,17 @@ Names are automatically cannonicalised (tidied up).
15
15
  bobby.last_name # => 'Fischer'
16
16
 
17
17
  In addition, players have a number of optional attributes which can be specified
18
- via setters or in constructor hash options: _id_ (either FIDE or national),
19
- _fed_ (federation), _title_, _rating_, _rank_ and _dob_ (date of birth).
18
+ via setters or in constructor hash options: _id_ (local or national ID), _fide_
19
+ (FIDE ID), _fed_ (federation), _title_, _rating_, _rank_ and _dob_ (date of birth).
20
20
 
21
21
  peter = ICU::Player.new('Peter', 'Svidler', 21, :fed => 'rus', :title => 'g', :rating = 2700)
22
22
  peter.dob = '17th June, 1976'
23
23
  peter.rank = 1
24
24
 
25
25
  Some of these values will also be canonicalised to some extent. For example,
26
- the date of birth conforms to a _yyyy-mm-dd_ format, the chess title will be two
26
+ date of birth will be turned into _yyyy-mm-dd_ format, the chess title will be two
27
27
  to three capital letters always ending in _M_ and the federation, if it's three
28
- letters long, will be upper-cased.
28
+ letters long, will be upcased.
29
29
 
30
30
  peter.dob # => 1976-07-17
31
31
  peter.title # => 'GM'
@@ -33,17 +33,18 @@ letters long, will be upper-cased.
33
33
 
34
34
  It is preferable to add results (ICU::Result) to a player via the tournament (ICU::Tournament) object's
35
35
  _add_result_ method rather than the method of the same name belonging to player instances. Doing so
36
- allows mirrored results to be added to both players with one method call (e.g. one player won, the
36
+ allows mirrored results to be added to both players with one call (e.g. one player won, so the
37
37
  other lost). A player's results can later be retieved via the _results_ accessor.
38
38
 
39
39
  Total scores is available via the _points_ method.
40
40
 
41
41
  peter.points # => 5.5
42
42
 
43
- A player's _id_ is their ID number in some external database (typically either ICU or FIDE).
43
+ A player can have up to two ID numbers (both positive integers or nil): _id_ (local or national ID,
44
+ such as ICU number) and _fide_ (FIDE ID).
44
45
 
45
- peter.id = 16790 # ICU, or
46
- peter.id = 4102142 # FIDE
46
+ peter.id = 16790 # ICU
47
+ peter.fide = 4102142 # FIDE
47
48
 
48
49
  Players can be compared to see if they're roughly or exactly the same, which may be useful in detecting duplicates.
49
50
  If the names match and the federations don't disagree then two players are equal according to the _==_ operator.
@@ -56,7 +57,7 @@ The player number is irrelevant.
56
57
  john1 == john2 # => true (federations don't disagree because one is unset)
57
58
  john2 == john3 # => false (federations disagree)
58
59
 
59
- If, in addition, _rating_, _dob_, _gender_ and _id_ do not disagree then two players are equal
60
+ If, in addition, _rating_, _dob_, _gender_, _id_ and _fide_ do not disagree then two players are equal
60
61
  according to the stricter criteria of _eql?_.
61
62
 
62
63
  mark1 = ICU::Player.new('Mark', 'Orr', 31, :fed = 'IRL', :rating => 2100)
@@ -69,7 +70,7 @@ according to the stricter criteria of _eql?_.
69
70
  The presence of two players in the same tournament that are equal according to _==_ but unequal
70
71
  according to _eql?__ is likely to indicate a data entry error.
71
72
 
72
- If two instances represent the same player and are equal according to _==_ then the _id_, _rating_,
73
+ If two instances represent the same player and are equal according to _==_ then the _id_, _fide_, _rating_,
73
74
  _title_ and _fed_ attributes of the two can be merged. For example:
74
75
 
75
76
  fox1 = ICU::Player.new('Tony', 'Fox', 12, :id => 456)
@@ -89,7 +90,7 @@ All other attributes are unaffected.
89
90
 
90
91
  extend ICU::Accessor
91
92
  attr_integer :num
92
- attr_positive_or_nil :id, :rating, :rank
93
+ attr_positive_or_nil :id, :fide, :rating, :rank
93
94
  attr_date_or_nil :dob
94
95
 
95
96
  attr_reader :results, :first_name, :last_name, :fed, :title, :gender
@@ -99,7 +100,7 @@ All other attributes are unaffected.
99
100
  self.first_name = first_name
100
101
  self.last_name = last_name
101
102
  self.num = num
102
- [:id, :fed, :title, :rating, :rank, :dob, :gender].each do |atr|
103
+ [:id, :fide, :fed, :title, :rating, :rank, :dob, :gender].each do |atr|
103
104
  self.send("#{atr}=", opt[atr]) unless opt[atr].nil?
104
105
  end
105
106
  @results = []
@@ -193,11 +194,11 @@ All other attributes are unaffected.
193
194
  true
194
195
  end
195
196
 
196
- # Strict equality test. Passes if the playes are loosly equal and also if their ID, rating, gender and title are not different.
197
+ # Strict equality test. Passes if the playes are loosly equal and also if their IDs, rating, gender and title are not different.
197
198
  def eql?(other)
198
199
  return true if equal?(other)
199
200
  return false unless self == other
200
- [:id, :rating, :title, :gender].each do |m|
201
+ [:id, :fide, :rating, :title, :gender].each do |m|
201
202
  return false if self.send(m) && other.send(m) && self.send(m) != other.send(m)
202
203
  end
203
204
  true
@@ -206,7 +207,7 @@ All other attributes are unaffected.
206
207
  # Merge in some of the details of another player.
207
208
  def merge(other)
208
209
  raise "cannot merge two players that are not equal" unless self == other
209
- [:id, :rating, :title, :fed, :gender].each do |m|
210
+ [:id, :fide, :rating, :title, :fed, :gender].each do |m|
210
211
  self.send("#{m}=", other.send(m)) unless self.send(m)
211
212
  end
212
213
  end
@@ -395,17 +395,19 @@ in which case any options supplied to this method will be silently ignored.
395
395
  type = format.to_s
396
396
  raise "Invalid format" unless type.match(/^(SwissPerfect|Krause|ForeignCSV)$/);
397
397
  parser = "ICU::Tournament::#{format}".constantize.new
398
- if type == 'SwissPerfect'
399
- parser.parse_file!(file, opts)
400
- else
398
+ if type == 'ForeignCSV'
399
+ # Doesn't take options.
401
400
  parser.parse_file!(file)
401
+ else
402
+ # The others can take options.
403
+ parser.parse_file!(file, opts)
402
404
  end
403
405
  end
404
406
 
405
407
  # Convenience method to serialise the tournament into a supported format.
406
408
  # Throws an exception unless the name of a supported format is supplied
407
409
  # or if the tournament is unsuitable for serialisation in that format.
408
- def serialize(format)
410
+ def serialize(format, arg={})
409
411
  serializer = case format.to_s.downcase
410
412
  when 'krause' then ICU::Tournament::Krause.new
411
413
  when 'foreigncsv' then ICU::Tournament::ForeignCSV.new
@@ -413,7 +415,7 @@ in which case any options supplied to this method will be silently ignored.
413
415
  when '' then raise "no format supplied"
414
416
  else raise "unsupported serialisation format: '#{format}'"
415
417
  end
416
- serializer.serialize(self)
418
+ serializer.serialize(self, arg)
417
419
  end
418
420
 
419
421
  private
@@ -205,7 +205,7 @@ For example, here are the commands to reproduce the example above.
205
205
  end
206
206
 
207
207
  # Serialise a tournament back into CSV format.
208
- def serialize(t)
208
+ def serialize(t, arg={})
209
209
  t.validate!(:type => self)
210
210
  Util::CSV.generate do |csv|
211
211
  csv << ["Event", t.name]
@@ -49,8 +49,17 @@ A player can be retrieved from the tournament via the _players_ array or by send
49
49
  daffy.rating # => 2200
50
50
  daffy.fed # => "IRL"
51
51
  daffy.id # => 7654321
52
+ daffy.fide # => nil
52
53
  daffy.dob # => "1937-04-17"
53
54
 
55
+ By default, ID numbers in the input are interpreted as local IDs. If, instead, they should be interpreted as
56
+ FIDE IDs, add the following option:
57
+
58
+ tournament = parser.parse_file('tournament.tab', :fide => true)
59
+ daffy = tournament.player(2)
60
+ daffy.id # => nil
61
+ daffy.fide # => 7654321
62
+
54
63
  If the ranking numbers are missing from the file or inconsistent (e.g. player A is ranked above player B
55
64
  but has less points than player B) they are recalculated as a side effect of the parse.
56
65
 
@@ -77,6 +86,12 @@ Or alternatively, by the _serialize_ method of the tournament object if the name
77
86
 
78
87
  krause = tournament.serialize('Krause')
79
88
 
89
+ By default, local (ICU) IDs are used for the serialization, but both methods accept an option that
90
+ causes FIDE IDs to be used instead:
91
+
92
+ krause = parser.serialize(tournament, :fide => true)
93
+ krause = parser.serialize(tournament, :fide => true)
94
+
80
95
  The following lists Krause data identification numbers, their description and, where available, their corresponding
81
96
  attributes in an ICU::Tournament instance.
82
97
 
@@ -102,7 +117,7 @@ attributes in an ICU::Tournament instance.
102
117
  attr_reader :error, :comments
103
118
 
104
119
  # Parse Krause data returning a Tournament on success or raising an exception on error.
105
- def parse!(krs)
120
+ def parse!(krs, arg={})
106
121
  @lineno = 0
107
122
  @tournament = Tournament.new('Dummy', '2000-01-01')
108
123
  @name_set, @start_set = false, false
@@ -116,7 +131,7 @@ attributes in an ICU::Tournament instance.
116
131
  next if line == '' # skip blank lines
117
132
  @line = line # remember this line for later
118
133
 
119
- # Does it havea DIN or is it just a comment?
134
+ # Does it have a DIN or is it just a comment?
120
135
  if @line.match(/^(\d{3}) (.*)$/)
121
136
  din = $1 # data identification number (DIN)
122
137
  @data = $2 # the data after the DIN
@@ -128,7 +143,7 @@ attributes in an ICU::Tournament instance.
128
143
  # Process the line given the DIN.
129
144
  begin
130
145
  case din
131
- when '001' then add_player # player and results record
146
+ when '001' then add_player(arg) # player and results record
132
147
  when '012' then set_name # name (mandatory)
133
148
  when '013' then add_team # team name and members
134
149
  when '022' then @tournament.city = @data # city
@@ -172,9 +187,9 @@ attributes in an ICU::Tournament instance.
172
187
 
173
188
  # Parse Krause data returning a Tournament on success or a nil on failure.
174
189
  # In the case of failure, an error message can be retrived via the <em>error</em> method.
175
- def parse(krs)
190
+ def parse(krs, arg={})
176
191
  begin
177
- parse!(krs)
192
+ parse!(krs, arg)
178
193
  rescue => ex
179
194
  @error = ex.message
180
195
  nil
@@ -182,15 +197,15 @@ attributes in an ICU::Tournament instance.
182
197
  end
183
198
 
184
199
  # Same as <em>parse!</em> except the input is a file name rather than file contents.
185
- def parse_file!(file)
200
+ def parse_file!(file, arg={})
186
201
  krause = open(file) { |f| f.read }
187
- parse!(krause)
202
+ parse!(krause, arg)
188
203
  end
189
204
 
190
205
  # Same as <em>parse</em> except the input is a file name rather than file contents.
191
- def parse_file(file)
206
+ def parse_file(file, arg={})
192
207
  begin
193
- parse_file!(file)
208
+ parse_file!(file, arg)
194
209
  rescue => ex
195
210
  @error = ex.message
196
211
  nil
@@ -198,7 +213,7 @@ attributes in an ICU::Tournament instance.
198
213
  end
199
214
 
200
215
  # Serialise a tournament back into Krause format.
201
- def serialize(t)
216
+ def serialize(t, arg={})
202
217
  t.validate!(:type => self)
203
218
  krause = ''
204
219
  krause << "012 #{t.name}\n"
@@ -221,7 +236,7 @@ attributes in an ICU::Tournament instance.
221
236
  t.round_dates.each{ |d| krause << d.sub(/^../, ' ') }
222
237
  krause << "\n"
223
238
  end
224
- t.players.each{ |p| krause << p.to_krause(rounds) }
239
+ t.players.each{ |p| krause << p.to_krause(rounds, arg) }
225
240
  krause
226
241
  end
227
242
 
@@ -242,7 +257,7 @@ attributes in an ICU::Tournament instance.
242
257
  @start_set = true
243
258
  end
244
259
 
245
- def add_player
260
+ def add_player(arg={})
246
261
  raise "player record less than minimum length" if @line.length < 99
247
262
 
248
263
  # Player details.
@@ -254,10 +269,10 @@ attributes in an ICU::Tournament instance.
254
269
  :title => @data[6, 3],
255
270
  :rating => @data[44, 4],
256
271
  :fed => @data[49, 3],
257
- :id => @data[53, 11],
258
272
  :dob => @data[65, 10],
259
273
  :rank => @data[81, 4],
260
274
  }
275
+ opt[arg[:fide] ? :fide : :id] = @data[53, 11]
261
276
  player = Player.new(nam.first, nam.last, num, opt)
262
277
  @tournament.add_player(player)
263
278
 
@@ -320,7 +335,7 @@ attributes in an ICU::Tournament instance.
320
335
 
321
336
  class Player
322
337
  # Format a player's 001 record as it would appear in a Krause formatted file (including the final newline).
323
- def to_krause(rounds)
338
+ def to_krause(rounds, arg)
324
339
  krause = '001'
325
340
  krause << sprintf(' %4d', @num)
326
341
  krause << sprintf(' %1s', case @gender; when 'M' then 'm'; when 'F' then 'w'; else ''; end)
@@ -328,7 +343,7 @@ attributes in an ICU::Tournament instance.
328
343
  krause << sprintf(' %-33s', "#{@last_name},#{@first_name}")
329
344
  krause << sprintf(' %4s', @rating)
330
345
  krause << sprintf(' %3s', @fed)
331
- krause << sprintf(' %11s', @id)
346
+ krause << sprintf(' %11s', arg[:fide] ? @fide : @id)
332
347
  krause << sprintf(' %10s', @dob)
333
348
  krause << sprintf(' %4.1f', points)
334
349
  krause << sprintf(' %4s', @rank)
@@ -43,16 +43,19 @@ If no start date is supplied it will default to 2000-01-01, and can be reset lat
43
43
  tournament.start # => '2000-01-01'
44
44
  tournament.start = '2010-07-03'
45
45
 
46
- By default, the parser extracts local ratings and IDs from the SwissPerfect files. If international
47
- ratings or IDs are required instead, use the options _id_ and _rating_. For example:
46
+ SwissPerfect files have slots for both local and international IDs and these, if present
47
+ and if intergers are copied to the _id_ and _fide_ attributes respectively.
48
+
49
+ By default, the parser extracts the local rating from the SwissPerfect files and not the international one.
50
+ If international ratings are required instead, set the _rating_ option to "intl". For example:
48
51
 
49
52
  tournament = parser.parse_file('ncc', :start => '2010-05-08')
50
53
  tournament.player(2).id # => 12379 (ICU ID)
51
- tournament.player(2).rating # => 2556 (ICU rating)
54
+ tournament.player(2).fide # => 1205064 (FIDE ID)
55
+ tournament.player(2).rating # => 2556 (ICU rating)
52
56
 
53
- tournament = parser.parse_file('ncc', :start => '2010-05-08', :id => 'intl', :rating => 'intl')
54
- tournament.player(2).id # => 1205064 (FIDE ID)
55
- tournament.player(2).rating # => 2530 (FIDE rating)
57
+ tournament = parser.parse_file('ncc', :start => '2010-05-08', :rating => 'intl')
58
+ tournament.player(2).rating # => 2530 (FIDE rating)
56
59
 
57
60
  By default, the parse will fail completely if the ".trn" file contains any invalid federations (see ICU::Federation).
58
61
  There are two alternative behaviours controlled by setting the _fed_ option:
@@ -109,7 +112,8 @@ See ICU::Tournament for more about tie-breaks.
109
112
  :fed => "FEDER",
110
113
  :first_name => "FIRSTNAME",
111
114
  :gender => "SEX",
112
- :id => ["LOC_ID", "INTL_ID"],
115
+ :id => "LOC_ID",
116
+ :fide => "INTL_ID",
113
117
  :last_name => "SURNAME",
114
118
  :num => "ID",
115
119
  :rank => "ORDER",
@@ -145,7 +149,7 @@ See ICU::Tournament for more about tie-breaks.
145
149
  end
146
150
 
147
151
  # Serialise a tournament to SwissPerfect text export format.
148
- def serialize(t)
152
+ def serialize(t, arg={})
149
153
  t.validate!(:type => self)
150
154
 
151
155
  # Ensure a nice set of numbers.
@@ -287,6 +291,7 @@ See ICU::Tournament for more about tie-breaks.
287
291
  when :fed then val = val && val.match(/^[A-Z]{3}$/i) ? val.upcase : nil
288
292
  when :gender then val = val.to_i > 0 ? %w(M F)[val.to_i-1] : nil
289
293
  when :id then val = val.to_i > 0 ? val : nil
294
+ when :fide then val = val.to_i > 0 ? val : nil
290
295
  when :rating then val = val.to_i > 0 ? val : nil
291
296
  when :title then val = val.to_i > 0 ? %w(GM WGM IM WIM FM WFM)[val.to_i-1] : nil
292
297
  end
@@ -1,5 +1,5 @@
1
1
  module ICU
2
2
  class Tournament
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
data/spec/player_spec.rb CHANGED
@@ -63,18 +63,30 @@ module ICU
63
63
  end
64
64
  end
65
65
 
66
- context "ID" do
66
+ context "local ID" do
67
67
  it "defaults to nil" do
68
68
  Player.new('Mark', 'Orr', 3).id.should be_nil
69
69
  end
70
70
 
71
71
  it "should be a positive integer" do
72
72
  Player.new('Mark', 'Orr', 3, :id => 1350).id.should == 1350
73
- Player.new('Gary', 'Kasparov', 4, :id => '4100018').id.should == 4100018
73
+ Player.new('Stephen', 'Brady', 4, :id => ' 90 ').id.should == 90
74
74
  lambda { Player.new('Mark', 'Orr', 3, :id => ' 0 ') }.should raise_error(/invalid positive integer/)
75
75
  end
76
76
  end
77
-
77
+
78
+ context "FIDE ID" do
79
+ it "defaults to nil" do
80
+ Player.new('Stephen', 'Brady', 1).fide.should be_nil
81
+ end
82
+
83
+ it "should be a positive integer" do
84
+ Player.new('Stephen', 'Brady', 1, :fide => 2500124).fide.should == 2500124
85
+ Player.new('Gary', 'Kasparov', 2, :fide => '4100018').fide.should == 4100018
86
+ lambda { Player.new('Mark', 'Orr', 3, :fide => ' 0 ') }.should raise_error(/invalid positive integer/)
87
+ end
88
+ end
89
+
78
90
  context "federation" do
79
91
  it "defaults to nil" do
80
92
  Player.new('Mark', 'Orr', 3).fed.should be_nil
@@ -212,8 +224,8 @@ module ICU
212
224
  context "merge" do
213
225
  before(:each) do
214
226
  @p1 = Player.new('Mark', 'Orr', 1, :id => 1350)
215
- @p2 = Player.new('Mark', 'Orr', 2, :rating => 2100, :title => 'IM', :fed => 'IRL')
216
- @p3 = Player.new('Gearoidin', 'Ui Laighleis', 3, :rating => 1600, :title => 'WIM', :fed => 'IRL')
227
+ @p2 = Player.new('Mark', 'Orr', 2, :rating => 2100, :title => 'IM', :fed => 'IRL', :fide => 2500035)
228
+ @p3 = Player.new('Gearoidin', 'Ui Laighleis', 3, :rating => 1600, :title => 'WIM', :fed => 'IRL', :fide => 2501171)
217
229
  end
218
230
 
219
231
  it "takes on the ID, rating, title and fed of the other player but not the player number" do
@@ -223,6 +235,7 @@ module ICU
223
235
  @p1.rating.should == 2100
224
236
  @p1.title.should == 'IM'
225
237
  @p1.fed.should == 'IRL'
238
+ @p1.fide.should == 2500035
226
239
  end
227
240
 
228
241
  it "should have a kind of symmetry" do
@@ -7,21 +7,17 @@ module ICU
7
7
  p = @t.player(num)
8
8
  p.first_name.should == first
9
9
  p.last_name.should == last
10
- p.gender.should == other[:gender]
11
- p.title.should == other[:title]
12
- p.rating.should == other[:rating]
13
- p.fed.should == other[:fed]
14
- p.id.should == other[:id]
15
- p.dob.should == other[:dob]
16
- p.rank.should == other[:rank]
10
+ [:gender, :title, :rating, :fed, :id, :fide, :dob, :rank].each do |key|
11
+ p.send(key).should == other[key] if other.has_key?(key)
12
+ end
17
13
  end
18
-
14
+
19
15
  def check_results(num, results, points)
20
16
  p = @t.player(num)
21
17
  p.results.size.should == results
22
18
  p.points.should == points
23
19
  end
24
-
20
+
25
21
  context "a typical tournament" do
26
22
  before(:all) do
27
23
  krause = <<KRAUSE
@@ -41,54 +37,54 @@ module ICU
41
37
  0 1 2 3 4 5 6 7 8 9 0 1 2
42
38
  0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
43
39
  132 08.06.07 08.06.08 08.06.09
44
- 001 1 w Ui Laighleis,Gearoidin 1985 IRL 2501171 1964.06.10 1.0 2 2 b 0 3 w 1
40
+ 001 1 w Ui Laighleis,Gearoidin 1985 IRL 2501171 1964.06.10 1.0 2 2 b 0 3 w 1
45
41
  001 2 m m Orr,Mark 2258 IRL 2500035 1955.11.09 2.0 1 1 w 1 3 b 1
46
42
  001 3 m g Bologan,Viktor 2663 MDA 13900048 1971.01.01 0.0 3 1 b 0 2 w 0
47
43
  KRAUSE
48
44
  @p = ICU::Tournament::Krause.new
49
45
  @t = @p.parse!(krause)
50
46
  end
51
-
47
+
52
48
  it "should have a name, city and federation" do
53
49
  @t.name.should == 'Las Vegas National Open'
54
50
  @t.city.should == 'Las Vegas'
55
51
  @t.fed.should == 'USA'
56
52
  end
57
-
53
+
58
54
  it "should have start and end dates" do
59
55
  @t.start.should == '2008-06-07'
60
56
  @t.finish.should == '2008-06-09'
61
57
  end
62
-
58
+
63
59
  it "should have a number of rounds, a type and a time control" do
64
60
  @t.rounds.should == 3
65
61
  @t.last_round.should == 3
66
62
  @t.type.should == 'All-Play-All'
67
63
  @t.time_control.should == '60 in 2hr, 30 in 1hr, rest in 1hr'
68
64
  end
69
-
65
+
70
66
  it "should have an arbiter and deputies" do
71
67
  @t.arbiter.should == 'Hans Scmidt'
72
68
  @t.deputy.should == 'Gerry Graham, Herbert Scarry'
73
69
  end
74
-
70
+
75
71
  it "should have players and their details" do
76
72
  @t.should have(3).players
77
73
  check_player(1, 'Gearoidin', 'Ui Laighleis', :gender => 'F', :rating => 1985, :fed => 'IRL', :id => 2501171, :dob => '1964-06-10', :rank => 2)
78
74
  check_player(2, 'Mark', 'Orr', :gender => 'M', :rating => 2258, :fed => 'IRL', :id => 2500035, :dob => '1955-11-09', :rank => 1, :title => 'IM')
79
75
  check_player(3, 'Viktor', 'Bologan', :gender => 'M', :rating => 2663, :fed => 'MDA', :id => 13900048, :dob => '1971-01-01', :rank => 3, :title => 'GM')
80
76
  end
81
-
77
+
82
78
  it "should have correct results for each player" do
83
79
  check_results(1, 2, 1.0)
84
80
  check_results(2, 2, 2.0)
85
81
  check_results(3, 2, 0.0)
86
82
  end
87
-
83
+
88
84
  it "should have correct round dates" do
89
85
  @t.round_dates.join('|').should == '2008-06-07|2008-06-08|2008-06-09'
90
86
  end
91
-
87
+
92
88
  it "the parser should retain comment lines" do
93
89
  comments = <<COMMENTS
94
90
  062 3
@@ -100,7 +96,7 @@ COMMENTS
100
96
  @p.comments.should == comments
101
97
  end
102
98
  end
103
-
99
+
104
100
  context "the documentation example" do
105
101
  before(:all) do
106
102
  krause = <<KRAUSE
@@ -109,7 +105,7 @@ COMMENTS
109
105
  042 2009.09.09
110
106
  0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
111
107
  132 09.09.09 09.09.10 09.09.11
112
- 001 1 w Mouse,Minerva 1900 USA 1234567 1928.05.15 1.0 2 2 b 0 3 w 1
108
+ 001 1 w Mouse,Minerva 1900 USA 1234567 1928.05.15 1.0 2 2 b 0 3 w 1
113
109
  001 2 m m Duck,Daffy 2200 IRL 7654321 1937.04.17 2.0 1 1 w 1 3 b 1
114
110
  001 3 m g Mouse,Mickey 2600 USA 1726354 1928.05.15 0.0 3 1 b 0 2 w 0
115
111
  KRAUSE
@@ -129,7 +125,7 @@ KRAUSE
129
125
  end
130
126
 
131
127
  it "should have a number of rounds" do
132
- @t.rounds.should == 3
128
+ @t.rounds.should == 3
133
129
  end
134
130
 
135
131
  it "should have players and their details" do
@@ -149,7 +145,7 @@ KRAUSE
149
145
  @p.comments.should == "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n"
150
146
  end
151
147
  end
152
-
148
+
153
149
  context "the README serialisation example" do
154
150
  before(:all) do
155
151
  @t = ICU::Tournament.new('World Championship', '1972-07-11')
@@ -166,12 +162,12 @@ KRAUSE
166
162
  it "should produce a valid tournament" do
167
163
  @t.invalid.should be_false
168
164
  end
169
-
165
+
170
166
  it "should produce output that looks reasonable" do
171
167
  @k.should match(/Fischer,Robert J\./)
172
168
  end
173
169
  end
174
-
170
+
175
171
  context "serialisation" do
176
172
  before(:each) do
177
173
  @krause = <<KRAUSE
@@ -193,17 +189,28 @@ KRAUSE
193
189
  001 4 wg Cramling,Pia 2500 SWE 1700030 1963-04-23 0.5 3 0000 - = 1 w 0
194
190
  KRAUSE
195
191
  @p = ICU::Tournament::Krause.new
196
- @t = @p.parse!(@krause)
197
- @q = ICU::Tournament::Krause.new
198
192
  end
199
193
 
200
194
  it "should serialize back to the original if the input is fully canonicalised" do
201
- @q.serialize(@t).should == @krause
195
+ t = @p.parse!(@krause)
196
+ ICU::Tournament::Krause.new.serialize(t).should == @krause
202
197
  end
203
-
198
+
204
199
  it "should serialize using the convenience method of the tournament object" do
205
- @t.serialize('Krause').should == @krause
200
+ t = @p.parse!(@krause)
201
+ t.serialize('Krause').should == @krause
202
+ end
203
+
204
+ it "should not serialize coorectly if mixed ID types are used" do
205
+ t = @p.parse!(@krause, :fide => true)
206
+ t.serialize('Krause').should_not == @krause
206
207
  end
208
+
209
+ it "should serialize coorectly if FIDE IDs are used consistently" do
210
+ t = @p.parse!(@krause, :fide => true)
211
+ t.serialize('Krause', :fide => true).should == @krause
212
+ end
213
+
207
214
  end
208
215
 
209
216
  context "auto-ranking" do
@@ -225,13 +232,40 @@ KRAUSE
225
232
  @t.player(3).rank.should == 3
226
233
  end
227
234
  end
228
-
235
+
236
+ context "local or FIDE IDs" do
237
+ before(:each) do
238
+ @krause = <<KRAUSE
239
+ 012 Las Vegas National Open
240
+ 042 2008-06-07
241
+ 001 1 w Ui Laighleis,Gearoidin 1985 IRL 2501171 1964-06-10 1.0 2 b 0 3 w 1
242
+ 001 2 m m Orr,Mark 2258 IRL 2500035 1955-11-09 2.0 1 w 1 3 b 1
243
+ 001 3 m g Bologan,Viktor 2663 MDA 1971-01-01 0.0 1 b 0 2 w 0
244
+ KRAUSE
245
+ @p = ICU::Tournament::Krause.new
246
+ end
247
+
248
+ it "should have local IDs by default" do
249
+ @t = @p.parse(@krause)
250
+ check_player(1, 'Gearoidin', 'Ui Laighleis', :id => 2501171, :fide => nil)
251
+ check_player(2, 'Mark', 'Orr', :id => 2500035, :fide => nil)
252
+ check_player(3, 'Viktor', 'Bologan', :id => nil, :fide => nil)
253
+ end
254
+
255
+ it "should have FIDE IDs if option is used" do
256
+ @t = @p.parse(@krause, :fide => true)
257
+ check_player(1, 'Gearoidin', 'Ui Laighleis', :fide => 2501171, :id => nil)
258
+ check_player(2, 'Mark', 'Orr', :fide => 2500035, :id => nil)
259
+ check_player(3, 'Viktor', 'Bologan', :fide => nil, :id => nil)
260
+ end
261
+ end
262
+
229
263
  context "renumbering" do
230
264
  before(:all) do
231
265
  @krause = <<KRAUSE
232
266
  012 Las Vegas National Open
233
267
  042 2008-06-07
234
- 001 10 w Ui Laighleis,Gearoidin 1985 IRL 1.0 20 b 0 30 w 1
268
+ 001 10 w Ui Laighleis,Gearoidin 1985 IRL 1.0 20 b 0 30 w 1
235
269
  001 20 m m Orr,Mark 2258 IRL 2.0 10 w 1 30 b 1
236
270
  001 30 m g Bologan,Viktor 2663 MDA 0.0 10 b 0 20 w 0
237
271
  KRAUSE
@@ -245,7 +279,7 @@ KRAUSE
245
279
  001 3 m g Bologan,Viktor 2663 MDA 0.0 3 2 b 0 1 w 0
246
280
  REORDERED
247
281
  end
248
-
282
+
249
283
  it "should serialise correctly after renumbering by rank" do
250
284
  @t.renumber
251
285
  @p.serialize(@t).should == @reordered
@@ -10,7 +10,7 @@ module ICU
10
10
  class Player
11
11
  def signature
12
12
  [
13
- name, id, rating, points, rank,
13
+ name, id, fide, rating, points, rank,
14
14
  results.map{ |r| r.round }.join(''),
15
15
  results.map{ |r| r.score }.join(''),
16
16
  results.map{ |r| r.colour || "-" }.join(''),
@@ -38,10 +38,10 @@ module ICU
38
38
  end
39
39
 
40
40
  it "should have correct details for selected players" do
41
- @t.player(2).signature.should == "Mullooly, Neil M.|6438|1083|6.0|1|123456|WWWWWW|WBWBWB|TTTTTT" # winner
42
- @t.player(4).signature.should == "Gallagher, Mark|12138|1036|4.0|9|123456|WLWWWL|WBWBWB|FTTTTT" # had one bye
43
- @t.player(45).signature.should == "Catre, Loredan||507|3.5|18|123456|WDLWLW|BWBWBW|FTTTFT" # had two byes
44
- @t.player(56).signature.should == "McDonnell, Cathal||498|0.0|54|1|L|-|F" # last
41
+ @t.player(2).signature.should == "Mullooly, Neil M.|6438||1083|6.0|1|123456|WWWWWW|WBWBWB|TTTTTT" # winner
42
+ @t.player(4).signature.should == "Gallagher, Mark|12138||1036|4.0|9|123456|WLWWWL|WBWBWB|FTTTTT" # had one bye
43
+ @t.player(45).signature.should == "Catre, Loredan|||507|3.5|18|123456|WDLWLW|BWBWBW|FTTTFT" # had two byes
44
+ @t.player(56).signature.should == "McDonnell, Cathal|||498|0.0|54|1|L|-|F" # last
45
45
  end
46
46
 
47
47
  it "should have consistent ranks" do
@@ -71,10 +71,10 @@ module ICU
71
71
  end
72
72
 
73
73
  it "should have correct details for selected players" do
74
- @t.player(1).signature.should == "Griffiths, Ryan-Rhys|6897|2225|3.0|1|123|WWW|WWB|TTT"
75
- @t.player(2).signature.should == "Flynn, Jamie|5226|1633|2.0|2|123|WLW|WBW|TTT"
76
- @t.player(3).signature.should == "Hulleman, Leon|6409|1466|1.0|3|123|LWL|BBW|TTT"
77
- @t.player(4).signature.should == "Dunne, Thomas|10914||0.0|4|123|LLL|BWB|TTT"
74
+ @t.player(1).signature.should == "Griffiths, Ryan-Rhys|6897||2225|3.0|1|123|WWW|WWB|TTT"
75
+ @t.player(2).signature.should == "Flynn, Jamie|5226||1633|2.0|2|123|WLW|WBW|TTT"
76
+ @t.player(3).signature.should == "Hulleman, Leon|6409||1466|1.0|3|123|LWL|BBW|TTT"
77
+ @t.player(4).signature.should == "Dunne, Thomas|10914|||0.0|4|123|LLL|BWB|TTT"
78
78
  end
79
79
 
80
80
  it "should have consistent ranks" do
@@ -103,12 +103,12 @@ module ICU
103
103
  end
104
104
 
105
105
  it "should have correct details for selected players" do
106
- @t.player(15).signature.should == "Talazec, Laurent|10692|1570|5.5|1|1234567|WWWDDDW|WWBWBWB|FTTTTTT" # winner
107
- @t.player(6).signature.should == "Foenander, Phillip|7168|1434|4.0|7|1234567|WLWLLWW|BWBWBWB|TTFFTTT" # had some byes
108
- @t.player(19).signature.should == "Wall, Robert|||3.0|14|34567|WWLWL|WWBBW|FTTTT" # didn't play 1st 2 rounds
109
- @t.player(17).signature.should == "Freeman, Conor|||2.0|16|1234567|DDLWLLL|--BWBWB|FFTTTTT" # had byes and bonus (in BONUS)
110
- @t.player(18).signature.should == "Freeman, Ruiri|||2.0|17|1234567|DDLLLLW|--WBBWB|FFTTTTF" # had byes and bonus (in BONUS)
111
- @t.player(16).signature.should == "O'Connor, David|||1.0|19|123|WLL|WBW|FTF" # last
106
+ @t.player(15).signature.should == "Talazec, Laurent|10692||1570|5.5|1|1234567|WWWDDDW|WWBWBWB|FTTTTTT" # winner
107
+ @t.player(6).signature.should == "Foenander, Phillip|7168||1434|4.0|7|1234567|WLWLLWW|BWBWBWB|TTFFTTT" # had some byes
108
+ @t.player(19).signature.should == "Wall, Robert||||3.0|14|34567|WWLWL|WWBBW|FTTTT" # didn't play 1st 2 rounds
109
+ @t.player(17).signature.should == "Freeman, Conor||||2.0|16|1234567|DDLWLLL|--BWBWB|FFTTTTT" # had byes and bonus (in BONUS)
110
+ @t.player(18).signature.should == "Freeman, Ruiri||||2.0|17|1234567|DDLLLLW|--WBBWB|FFTTTTF" # had byes and bonus (in BONUS)
111
+ @t.player(16).signature.should == "O'Connor, David||||1.0|19|123|WLL|WBW|FTF" # last
112
112
  end
113
113
 
114
114
  it "should have consistent ranks" do
@@ -133,10 +133,10 @@ module ICU
133
133
  end
134
134
 
135
135
  it "should have correct details for selected players" do
136
- @t.player(15).signature.should == "Gupta, Radhika||1247|3.0|1|123|WWW|BBW|TTT" # won all his games
137
- @t.player(18).signature.should == "Hurley, Thomas|6292|820|1.0|14|1|W|B|F" # scored just 1 from a bye in R1
138
- @t.player(8).signature.should == "Berney, Mark|10328|1948|2.0|3|23|WW|BW|TT" # didn't play in round 1
139
- @t.player(10).signature.should == "O'Donnell, Conor E.|10792|1073|2.0|10|123|LWW|WBW|TFT" # got just 1 point for a bye
136
+ @t.player(15).signature.should == "Gupta, Radhika|||1247|3.0|1|123|WWW|BBW|TTT" # won all his games
137
+ @t.player(18).signature.should == "Hurley, Thomas|6292||820|1.0|14|1|W|B|F" # scored just 1 from a bye in R1
138
+ @t.player(8).signature.should == "Berney, Mark|10328||1948|2.0|3|23|WW|BW|TT" # didn't play in round 1
139
+ @t.player(10).signature.should == "O'Donnell, Conor E.|10792||1073|2.0|10|123|LWW|WBW|TFT" # got just 1 point for a bye
140
140
  end
141
141
 
142
142
  it "should have consistent ranks" do
@@ -161,11 +161,11 @@ module ICU
161
161
  end
162
162
 
163
163
  it "should have correct details for selection of players who got bonuses (in MEMO)" do
164
- @t.player(23).signature.should == "Long, Killian|10293|1506|2.5|33|123456|WDLLWL|WWBWBB|TFTTTT"
165
- @t.player(26).signature.should == "Bradley, Michael|6756|1413|3.0|26|123456|DDLWWL|BWWBWW|TFTTTT"
166
- @t.player(15).signature.should == "Twomey, Pat|1637|1656|4.5|7|123456|WDLWWW|WWWBWB|FFTTTT"
167
- @t.player(46).signature.should == "O'Riordan, Pat|10696|900|2.0|42|123456|LDDLDD|BWBWWB|TTTTFT"
168
- @t.player(38).signature.should == "Gill, Craig I.|10637|1081|2.0|43|123456|LLWDDL|BWBWWB|TTTTFT"
164
+ @t.player(23).signature.should == "Long, Killian|10293|2|1506|2.5|33|123456|WDLLWL|WWBWBB|TFTTTT"
165
+ @t.player(26).signature.should == "Bradley, Michael|6756|27|1413|3.0|26|123456|DDLWWL|BWWBWW|TFTTTT"
166
+ @t.player(15).signature.should == "Twomey, Pat|1637|22|1656|4.5|7|123456|WDLWWW|WWWBWB|FFTTTT"
167
+ @t.player(46).signature.should == "O'Riordan, Pat|10696||900|2.0|42|123456|LDDLDD|BWBWWB|TTTTFT"
168
+ @t.player(38).signature.should == "Gill, Craig I.|10637|28|1081|2.0|43|123456|LLWDDL|BWBWWB|TTTTFT"
169
169
  end
170
170
 
171
171
  it "should have consistent ranks" do
@@ -186,18 +186,18 @@ module ICU
186
186
  end
187
187
 
188
188
  it "should have correct details for selection of players, including ICU IDs" do
189
- @t.player(2).signature.should == "Szabo, Gergely|12379|2530|4.0|4|1234|WWWW|WBWB|TTTT"
190
- @t.player(5).signature.should == "Daly, Colm|295|2314|3.5|7|1234|WWWD|WBWB|TTTT"
191
- @t.player(8).signature.should == "Vega, Marcos Llaneza||2475|3.0|16|1234|DDWW|BWBW|TTTT"
192
- @t.player(67).signature.should == "Lee, Shane|780|1633|1.0|52|134|DLD|WWW|TTT"
189
+ @t.player(2).signature.should == "Szabo, Gergely|12379|1205064|2530|4.0|4|1234|WWWW|WBWB|TTTT"
190
+ @t.player(5).signature.should == "Daly, Colm|295|2500434|2314|3.5|7|1234|WWWD|WBWB|TTTT"
191
+ @t.player(8).signature.should == "Vega, Marcos Llaneza||2253585|2475|3.0|16|1234|DDWW|BWBW|TTTT"
192
+ @t.player(67).signature.should == "Lee, Shane|780||1633|1.0|52|134|DLD|WWW|TTT"
193
193
  end
194
194
 
195
- it "should have correct details for selection of players, including international IDs and ratings when so configured" do
196
- @t = @p.parse_file(SAMPLES + 'ncc', :start => "2010-05-08", :id => 'intl', :rating => :intl)
197
- @t.player(2).signature.should == "Szabo, Gergely|1205064||4.0|4|1234|WWWW|WBWB|TTTT"
198
- @t.player(5).signature.should == "Daly, Colm|2500434||3.5|7|1234|WWWD|WBWB|TTTT"
199
- @t.player(8).signature.should == "Vega, Marcos Llaneza|2253585||3.0|16|1234|DDWW|BWBW|TTTT"
200
- @t.player(67).signature.should == "Lee, Shane|||1.0|52|134|DLD|WWW|TTT"
195
+ it "should have correct details for selection of players, including international ratings when so configured" do
196
+ @t = @p.parse_file(SAMPLES + 'ncc', :start => "2010-05-08", :rating => :intl)
197
+ @t.player(2).signature.should == "Szabo, Gergely|12379|1205064||4.0|4|1234|WWWW|WBWB|TTTT"
198
+ @t.player(5).signature.should == "Daly, Colm|295|2500434||3.5|7|1234|WWWD|WBWB|TTTT"
199
+ @t.player(8).signature.should == "Vega, Marcos Llaneza||2253585||3.0|16|1234|DDWW|BWBW|TTTT"
200
+ @t.player(67).signature.should == "Lee, Shane|780|||1.0|52|134|DLD|WWW|TTT"
201
201
  end
202
202
  end
203
203
 
@@ -293,10 +293,10 @@ module ICU
293
293
  end
294
294
 
295
295
  it "should have correct details for selection of players, including ICU IDs" do
296
- @t.player(2).signature.should == "Szabo, Gergely|12379|2530|4.0|4|1234|WWWW|WBWB|TTTT"
297
- @t.player(5).signature.should == "Daly, Colm|295|2314|3.5|7|1234|WWWD|WBWB|TTTT"
298
- @t.player(8).signature.should == "Vega, Marcos Llaneza||2475|3.0|16|1234|DDWW|BWBW|TTTT"
299
- @t.player(67).signature.should == "Lee, Shane|780|1633|1.0|52|134|DLD|WWW|TTT"
296
+ @t.player(2).signature.should == "Szabo, Gergely|12379|1205064|2530|4.0|4|1234|WWWW|WBWB|TTTT"
297
+ @t.player(5).signature.should == "Daly, Colm|295|2500434|2314|3.5|7|1234|WWWD|WBWB|TTTT"
298
+ @t.player(8).signature.should == "Vega, Marcos Llaneza||2253585|2475|3.0|16|1234|DDWW|BWBW|TTTT"
299
+ @t.player(67).signature.should == "Lee, Shane|780||1633|1.0|52|134|DLD|WWW|TTT"
300
300
  end
301
301
  end
302
302
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
- - 0
9
- version: 1.1.0
8
+ - 1
9
+ version: 1.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark Orr
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-17 00:00:00 +01:00
17
+ date: 2010-10-18 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency