icu_tournament 1.3.7 → 1.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -94,20 +94,25 @@ module ICU
94
94
  #
95
95
  # t.validate(:rerank => true)
96
96
  #
97
- # Ranking is inconsistent if some but not all players have a rank or if all players
98
- # but at least one pair of players exist where one has a higher score but a lower rank.
97
+ # Ranking is inconsistent if not all players have a rank or at least one pair of players exist
98
+ # where one has a higher score but a lower rank.
99
99
  #
100
- # To rank the players requires a tie break method to be specified to order players on the same score.
101
- # The default is alphabetical (by last name then first name). Other methods can be specified by supplying
102
- # an array of methods (strings or symbols) in order of precedence to the _tie_breaks_ setter. Examples:
100
+ # To rank the players requires one or more tie break methods for ordering players on the same score.
101
+ # Methods can be specified by supplying an array of methods names (strings or symbols) in order of
102
+ # precedence to the _tie_breaks_ setter. Examples:
103
103
  #
104
104
  # t.tie_breaks = ['Sonneborn-Berger']
105
105
  # t.tie_breaks = [:buchholz, :neustadtl, :blacks, :wins]
106
- # t.tie_breaks = [] # reset to the default
106
+ # t.tie_breaks = [] # use the default - see below
107
107
  #
108
- # See ICU::TieBreak for the full list of supported tie break methods.
108
+ # If the first method fails to differentiate two tied players, the second is tried, and then the
109
+ # third and so on. See ICU::TieBreak for the full list of supported tie break methods.
109
110
  #
110
- # The return value from _rerank_ is the tournament object itself, to allow chaining, for example:
111
+ # Unless explicity specified, the _name_ tie break (which orders alphabetically by last name
112
+ # then first name) is implicitly used as a method of last resort. Thus, in the absence of any
113
+ # tie break methods being specified at all, alphabetical ordering is the default.
114
+ #
115
+ # The return value from _rerank_ is the tournament object itself, to allow method chaining, for example:
111
116
  #
112
117
  # t.rerank.renumber
113
118
  #
@@ -43,23 +43,25 @@ module ICU
43
43
  # daffy = tournament.player(2)
44
44
  # daffy.title # => "IM"
45
45
  # daffy.rating # => 2200
46
+ # daffy.fide_rating # => nil
46
47
  # daffy.fed # => "IRL"
47
- # daffy.id # => 7654321
48
- # daffy.fide # => nil
48
+ # daffy.id # => nil
49
+ # daffy.fide_id # => 7654321
49
50
  # daffy.dob # => "1937-04-17"
50
51
  #
51
- # By default, ID numbers and ratings in the input are interpreted as local IDs and ratings. If, instead, they should be interpreted as
52
- # FIDE IDs and ratings, add the following option:
52
+ # By default, ratings are interpreted as ICU. If, instead, they should be interpreted as
53
+ # FIDE ratings, add the _fide_ option:
53
54
  #
54
- # tournament = parser.parse_file('tournament.tab', :fide_id => true)
55
+ # tournament = parser.parse_file('tournament.tab', :fide => true)
55
56
  # daffy = tournament.player(2)
56
- # daffy.id # => nil
57
- # daffy.fide # => 7654321
58
57
  # daffy.rating # => nil
59
58
  # daffy.fide_rating # => 2200
60
59
  #
60
+ # ID numbers, on the other hand, are automatically classified as either FIDE or ICU on the basis of size,
61
+ # since all FIDE IDs are greater than 100000 whereas ICU IDs are much smaller.
62
+ #
61
63
  # If the ranking numbers are missing from the file or inconsistent (e.g. player A is ranked above player B
62
- # but has less points than player B) they are recalculated as a side effect of the parse.
64
+ # but has less points) they are recalculated as a side effect of the parse.
63
65
  #
64
66
  # daffy.rank # => 1
65
67
  # minnie.rank # => 2
@@ -87,8 +89,8 @@ module ICU
87
89
  # By default, local (ICU) IDs and ratings are used for the serialization, but both methods accept an option that
88
90
  # causes FIDE IDs and ratings to be used instead:
89
91
  #
90
- # krause = parser.serialize(tournament, :fide_id => true)
91
- # krause = tournament.serialize('Krause', :fide_id => true)
92
+ # krause = parser.serialize(tournament, :fide => true)
93
+ # krause = tournament.serialize('Krause', :fide => true)
92
94
  #
93
95
  # The following lists Krause data identification numbers, their description and, where available, their corresponding
94
96
  # attributes in an ICU::Tournament instance.
@@ -316,7 +318,7 @@ module ICU
316
318
  @tournament.start = @data
317
319
  @start_set = true
318
320
  end
319
-
321
+
320
322
  # Split text into lines but also pad the player lines (those beginning "001 ").
321
323
  def get_lines(text)
322
324
  lines = text.split(/\s*\n/)
@@ -352,17 +354,15 @@ module ICU
352
354
  :dob => @data[65, 10],
353
355
  :rank => @data[81, 4],
354
356
  }
355
-
356
- # The IDs and ratings can be local or international.
357
- itype = arg[:fide] ? :fide_id : :id
358
- rtype = arg[:fide] ? :fide_rating : :rating
359
- opt[itype] = @data[53, 11]
360
- opt[rtype] = @data[44, 4]
361
-
362
- # Remove obviously bad data.
363
- opt.delete(itype) if opt.has_key?(itype) && opt[itype].to_i == 0
364
- opt.delete(rtype) if opt.has_key?(rtype) && opt[rtype].to_i == 0
365
-
357
+
358
+ # Ratings are assumed to be local unless otherwise specified.
359
+ rating = @data[44, 4].to_i
360
+ opt[arg[:fide] ? :fide_rating : :rating] = rating if rating > 0 && rating < 4000
361
+
362
+ # IDs can be determined to be FIDE or ICU on the basis of their size.
363
+ id = @data[53, 11].to_i
364
+ opt[id >= 100000 ? :fide_id : :id] = id if id > 0
365
+
366
366
  # Options to remove other bad data.
367
367
  opt.delete(:fed) if arg[:fed].to_s == 'ignore'
368
368
  opt.delete(:fed) if arg[:fed].to_s == 'skip' && !ICU::Federation.find(opt[:fed])
@@ -414,7 +414,7 @@ module ICU
414
414
  end
415
415
  result.points
416
416
  end
417
-
417
+
418
418
  # See if byes can be used to make the sum of scores match the declared total.
419
419
  def fix_sum(player, full_byes, half_byes, total, sum)
420
420
  return false unless total > sum
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ICU
4
4
  class Tournament
5
- VERSION = "1.3.7"
5
+ VERSION = "1.3.8"
6
6
  end
7
7
  end
@@ -131,9 +131,9 @@ KRAUSE
131
131
 
132
132
  it "should have players and their details" do
133
133
  @t.should have(3).players
134
- check_player(1, 'Minerva', 'Mouse', :gender => 'F', :rating => 1900, :fed => 'USA', :id => 1234567, :dob => '1928-05-15', :rank => 2)
135
- check_player(2, 'Daffy', 'Duck', :gender => 'M', :rating => 2200, :fed => 'IRL', :id => 7654321, :dob => '1937-04-17', :rank => 1, :title => 'IM')
136
- check_player(3, 'Mickey', 'Mouse', :gender => 'M', :rating => 2600, :fed => 'USA', :id => 1726354, :dob => '1928-05-15', :rank => 3, :title => 'GM')
134
+ check_player(1, 'Minerva', 'Mouse', :gender => 'F', :rating => 1900, :fed => 'USA', :fide_id => 1234567, :dob => '1928-05-15', :rank => 2)
135
+ check_player(2, 'Daffy', 'Duck', :gender => 'M', :rating => 2200, :fed => 'IRL', :fide_id => 7654321, :dob => '1937-04-17', :rank => 1, :title => 'IM')
136
+ check_player(3, 'Mickey', 'Mouse', :gender => 'M', :rating => 2600, :fed => 'USA', :fide_id => 1726354, :dob => '1928-05-15', :rank => 3, :title => 'GM')
137
137
  end
138
138
 
139
139
  it "should have correct results for each player" do
@@ -193,13 +193,13 @@ KRAUSE
193
193
  end
194
194
 
195
195
  it "should serialize back to the original if the input is fully canonicalised" do
196
- t = @p.parse!(@krause)
197
- ICU::Tournament::Krause.new.serialize(t).should == @krause
196
+ t = @p.parse!(@krause, :fide => true)
197
+ ICU::Tournament::Krause.new.serialize(t, :fide => true).should == @krause
198
198
  end
199
199
 
200
200
  it "should serialize using the convenience method of the tournament object" do
201
- t = @p.parse!(@krause)
202
- t.serialize('Krause').should == @krause
201
+ t = @p.parse!(@krause, :fide => true)
202
+ t.serialize('Krause', :fide => true).should == @krause
203
203
  end
204
204
 
205
205
  it "should serialize only if :fide option is used correctly" do
@@ -208,16 +208,10 @@ KRAUSE
208
208
  t.serialize('Krause').should_not == @krause
209
209
  end
210
210
 
211
- it "should not serialize coorectly if mixed ID types are used" do
211
+ it "should not serialize correctly if mixed rating types are used" do
212
212
  t = @p.parse!(@krause, :fide => true)
213
213
  t.serialize('Krause').should_not == @krause
214
214
  end
215
-
216
- it "should serialize coorectly if FIDE IDs are used consistently" do
217
- t = @p.parse!(@krause, :fide => true)
218
- t.serialize('Krause', :fide => true).should == @krause
219
- end
220
-
221
215
  end
222
216
 
223
217
  context "auto-ranking" do
@@ -240,30 +234,39 @@ KRAUSE
240
234
  end
241
235
  end
242
236
 
243
- context "local or FIDE IDs" do
237
+ context "local or FIDE ratings and IDs" do
244
238
  before(:each) do
245
239
  @krause = <<KRAUSE
246
240
  012 Las Vegas National Open
247
241
  042 2008-06-07
248
242
  001 1 w Ui Laighleis,Gearoidin 1985 IRL 2501171 1964-06-10 1.0 2 b 0 3 w 1
249
- 001 2 m m Orr,Mark 2258 IRL 2500035 1955-11-09 2.0 1 w 1 3 b 1
243
+ 001 2 m m Orr,Mark 2258 IRL 1350 1955-11-09 2.0 1 w 1 3 b 1
250
244
  001 3 m g Bologan,Viktor 2663 MDA 1971-01-01 0.0 1 b 0 2 w 0
251
245
  KRAUSE
252
246
  @p = ICU::Tournament::Krause.new
253
247
  end
254
248
 
255
- it "should have local IDs by default" do
249
+ it "should have local ratings by default" do
256
250
  @t = @p.parse(@krause)
257
- check_player(1, 'Gearoidin', 'Ui Laighleis', :id => 2501171, :fide_id => nil)
258
- check_player(2, 'Mark', 'Orr', :id => 2500035, :fide_id => nil)
259
- check_player(3, 'Viktor', 'Bologan', :id => nil, :fide_id => nil)
251
+ check_player(1, 'Gearoidin', 'Ui Laighleis', :rating => 1985, :fide_rating => nil)
252
+ check_player(2, 'Mark', 'Orr', :rating => 2258, :fide_rating => nil)
253
+ check_player(3, 'Viktor', 'Bologan', :rating => 2663, :fide_rating => nil)
260
254
  end
261
255
 
262
- it "should have FIDE IDs if option is used" do
256
+ it "should have FIDE ratings if option is specified" do
257
+ @t = @p.parse(@krause, :fide => true)
258
+ check_player(1, 'Gearoidin', 'Ui Laighleis', :rating => nil, :fide_rating => 1985)
259
+ check_player(2, 'Mark', 'Orr', :rating => nil, :fide_rating => 2258)
260
+ check_player(3, 'Viktor', 'Bologan', :rating => nil, :fide_rating => 2663)
261
+ end
262
+
263
+ it "should auto-detect FIDE or ICU IDs based on size, the option has no effect" do
264
+ @t = @p.parse(@krause)
265
+ check_player(1, 'Gearoidin', 'Ui Laighleis', :id => nil, :fide_id => 2501171)
266
+ check_player(2, 'Mark', 'Orr', :id => 1350, :fide_id => nil)
263
267
  @t = @p.parse(@krause, :fide => true)
264
- check_player(1, 'Gearoidin', 'Ui Laighleis', :fide => 2501171, :id => nil)
265
- check_player(2, 'Mark', 'Orr', :fide => 2500035, :id => nil)
266
- check_player(3, 'Viktor', 'Bologan', :fide => nil, :id => nil)
268
+ check_player(1, 'Gearoidin', 'Ui Laighleis', :id => nil, :fide_id => 2501171)
269
+ check_player(2, 'Mark', 'Orr', :id => 1350, :fide_id => nil)
267
270
  end
268
271
  end
269
272
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 3
8
- - 7
9
- version: 1.3.7
8
+ - 8
9
+ version: 1.3.8
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: 2011-03-04 00:00:00 +00:00
17
+ date: 2011-03-06 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency