icu_tournament 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -84,7 +84,7 @@ module ICU
84
84
  class Player
85
85
  extend ICU::Accessor
86
86
  attr_integer :num
87
- attr_positive_or_nil :id, :fide, :rating, :fide_rating, :rank
87
+ attr_positive_or_nil :id, :fide_id, :rating, :fide_rating, :rank
88
88
  attr_date_or_nil :dob
89
89
 
90
90
  attr_reader :results, :first_name, :last_name, :fed, :title, :gender
@@ -94,7 +94,7 @@ module ICU
94
94
  self.first_name = first_name
95
95
  self.last_name = last_name
96
96
  self.num = num
97
- [:id, :fide, :fed, :title, :rating, :fide_rating, :rank, :dob, :gender].each do |atr|
97
+ [:id, :fide_id, :fed, :title, :rating, :fide_rating, :rank, :dob, :gender].each do |atr|
98
98
  self.send("#{atr}=", opt[atr]) unless opt[atr].nil?
99
99
  end
100
100
  @results = []
@@ -192,7 +192,7 @@ module ICU
192
192
  def eql?(other)
193
193
  return true if equal?(other)
194
194
  return false unless self == other
195
- [:id, :fide, :rating, :fide_rating, :title, :gender].each do |m|
195
+ [:id, :fide_id, :rating, :fide_rating, :title, :gender].each do |m|
196
196
  return false if self.send(m) && other.send(m) && self.send(m) != other.send(m)
197
197
  end
198
198
  true
@@ -201,7 +201,7 @@ module ICU
201
201
  # Merge in some of the details of another player.
202
202
  def merge(other)
203
203
  raise "cannot merge two players that are not equal" unless self == other
204
- [:id, :fide, :rating, :fide_rating, :title, :fed, :gender].each do |m|
204
+ [:id, :fide_id, :rating, :fide_rating, :title, :fed, :gender].each do |m|
205
205
  self.send("#{m}=", other.send(m)) unless self.send(m)
206
206
  end
207
207
  end
@@ -51,7 +51,7 @@ module ICU
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
52
  # FIDE IDs and ratings, add the following option:
53
53
  #
54
- # tournament = parser.parse_file('tournament.tab', :fide => true)
54
+ # tournament = parser.parse_file('tournament.tab', :fide_id => true)
55
55
  # daffy = tournament.player(2)
56
56
  # daffy.id # => nil
57
57
  # daffy.fide # => 7654321
@@ -87,8 +87,8 @@ module ICU
87
87
  # By default, local (ICU) IDs and ratings are used for the serialization, but both methods accept an option that
88
88
  # causes FIDE IDs and ratings to be used instead:
89
89
  #
90
- # krause = parser.serialize(tournament, :fide => true)
91
- # krause = tournament.serialize('Krause', :fide => true)
90
+ # krause = parser.serialize(tournament, :fide_id => true)
91
+ # krause = tournament.serialize('Krause', :fide_id => true)
92
92
  #
93
93
  # The following lists Krause data identification numbers, their description and, where available, their corresponding
94
94
  # attributes in an ICU::Tournament instance.
@@ -270,7 +270,7 @@ module ICU
270
270
  :dob => @data[65, 10],
271
271
  :rank => @data[81, 4],
272
272
  }
273
- opt[arg[:fide] ? :fide : :id] = @data[53, 11]
273
+ opt[arg[:fide] ? :fide_id : :id] = @data[53, 11]
274
274
  opt[arg[:fide] ? :fide_rating : :rating] = @data[44, 4]
275
275
  player = Player.new(nam.first, nam.last, num, opt)
276
276
  @tournament.add_player(player)
@@ -342,7 +342,7 @@ module ICU
342
342
  krause << sprintf(' %-33s', "#{@last_name},#{@first_name}")
343
343
  krause << sprintf(' %4s', arg[:fide] ? @fide_rating : @rating)
344
344
  krause << sprintf(' %3s', @fed)
345
- krause << sprintf(' %11s', arg[:fide] ? @fide : @id)
345
+ krause << sprintf(' %11s', arg[:fide] ? @fide_id : @id)
346
346
  krause << sprintf(' %10s', @dob)
347
347
  krause << sprintf(' %4.1f', points)
348
348
  krause << sprintf(' %4s', @rank)
@@ -68,7 +68,7 @@ module ICU
68
68
  :first_name => "FIRSTNAME",
69
69
  :gender => "SEX",
70
70
  :id => "LOC_ID",
71
- :fide => "INTL_ID",
71
+ :fide_id => "INTL_ID",
72
72
  :last_name => "SURNAME",
73
73
  :num => "ID",
74
74
  :rank => "ORDER",
@@ -249,7 +249,7 @@ module ICU
249
249
  when :fed then val = val && val.match(/^[A-Z]{3}$/i) ? val.upcase : nil
250
250
  when :gender then val = val.to_i > 0 ? %w(M F)[val.to_i-1] : nil
251
251
  when :id then val = val.to_i > 0 ? val : nil
252
- when :fide then val = val.to_i > 0 ? val : nil
252
+ when :fide_id then val = val.to_i > 0 ? val : nil
253
253
  when :rating then val = val.to_i > 0 ? val : nil
254
254
  when :fide_rating then val = val.to_i > 0 ? val : nil
255
255
  when :title then val = val.to_i > 0 ? %w(GM WGM IM WIM FM WFM)[val.to_i-1] : nil
@@ -78,7 +78,7 @@ module ICU
78
78
  #
79
79
  # Or supply whatever columns you want, for example:
80
80
  #
81
- # tournament.serialize('SPExport', :columns => [:fide, :fide_rating])
81
+ # tournament.serialize('SPExport', :columns => [:fide_id, :fide_rating])
82
82
  #
83
83
  # Note that the column order in the serialised string is the same as it is in the SwissPerfect application.
84
84
  # The order of column names in the _columns_ hash has no effect.
@@ -189,7 +189,7 @@ module ICU
189
189
  columns = Array.new
190
190
  columns.push(:num)
191
191
  columns.push(:name)
192
- [:fed, :fide, :id, :fide_rating, :rating, :title, :points].each { |x| columns.push(x) if optional.include?(x) }
192
+ [:fed, :fide_id, :id, :fide_rating, :rating, :title, :points].each { |x| columns.push(x) if optional.include?(x) }
193
193
 
194
194
  # SwissPerfect headers for each column (other than the rounds, which are treated separately).
195
195
  header = Hash.new
@@ -198,7 +198,7 @@ module ICU
198
198
  when :num then "No"
199
199
  when :name then "Name"
200
200
  when :fed then "Feder"
201
- when :fide then "Intl Id"
201
+ when :fide_id then "Intl Id"
202
202
  when :id then "Loc Id"
203
203
  when :fide_rating then "Rtg"
204
204
  when :rating then "Loc"
@@ -259,13 +259,13 @@ module ICU
259
259
  key = case item
260
260
  when 'No' then :num
261
261
  when 'Name' then :name
262
- when 'Total' then :total
263
- when 'Loc Id' then :id
264
- when 'Intl Id' then :fide
265
- when 'Title' then :title
266
262
  when 'Feder' then :fed
267
- when 'Loc' then :rating
263
+ when 'Intl Id' then :fide_id
264
+ when 'Loc Id' then :id
268
265
  when 'Rtg' then :fide_rating
266
+ when 'Loc' then :rating
267
+ when 'Title' then :title
268
+ when 'Total' then :points
269
269
  when /^[1-9]\d*$/
270
270
  round = item.to_i
271
271
  @rounds = round if round > @rounds
@@ -287,7 +287,7 @@ module ICU
287
287
  num = items[@header[:num]]
288
288
  name = Name.new(items[@header[:name]])
289
289
  opt = Hash.new
290
- [:fed, :title, :id, :fide, :rating, :fide_rating].each do |key|
290
+ [:fed, :title, :id, :fide_id, :rating, :fide_rating].each do |key|
291
291
  if @header[key]
292
292
  val = items[@header[key]]
293
293
  opt[key] = val unless val.nil? || val == ''
@@ -299,7 +299,7 @@ module ICU
299
299
  @tournament.add_player(player)
300
300
 
301
301
  # Save the results for later processing.
302
- points = items[@header[:total]] if @header[:total]
302
+ points = items[@header[:points]] if @header[:points]
303
303
  points = nil if points == ''
304
304
  points = points.to_f if points
305
305
  total = 0.0;
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ICU
4
4
  class Tournament
5
- VERSION = "1.3.1"
5
+ VERSION = "1.3.2"
6
6
  end
7
7
  end
data/spec/player_spec.rb CHANGED
@@ -77,13 +77,13 @@ module ICU
77
77
 
78
78
  context "FIDE ID" do
79
79
  it "defaults to nil" do
80
- Player.new('Stephen', 'Brady', 1).fide.should be_nil
80
+ Player.new('Stephen', 'Brady', 1).fide_id.should be_nil
81
81
  end
82
82
 
83
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/)
84
+ Player.new('Stephen', 'Brady', 1, :fide_id => 2500124).fide_id.should == 2500124
85
+ Player.new('Gary', 'Kasparov', 2, :fide_id => '4100018').fide_id.should == 4100018
86
+ lambda { Player.new('Mark', 'Orr', 3, :fide_id => ' 0 ') }.should raise_error(/invalid positive integer/)
87
87
  end
88
88
  end
89
89
 
@@ -238,8 +238,8 @@ module ICU
238
238
  context "merge" do
239
239
  before(:each) do
240
240
  @p1 = Player.new('Mark', 'Orr', 1, :id => 1350)
241
- @p2 = Player.new('Mark', 'Orr', 2, :rating => 2100, :title => 'IM', :fed => 'IRL', :fide => 2500035)
242
- @p3 = Player.new('Gearoidin', 'Ui Laighleis', 3, :rating => 1600, :title => 'WIM', :fed => 'IRL', :fide => 2501171)
241
+ @p2 = Player.new('Mark', 'Orr', 2, :rating => 2100, :title => 'IM', :fed => 'IRL', :fide_id => 2500035)
242
+ @p3 = Player.new('Gearoidin', 'Ui Laighleis', 3, :rating => 1600, :title => 'WIM', :fed => 'IRL', :fide_id => 2501171)
243
243
  end
244
244
 
245
245
  it "takes on the ID, rating, title and fed of the other player but not the player number" do
@@ -249,7 +249,7 @@ module ICU
249
249
  @p1.rating.should == 2100
250
250
  @p1.title.should == 'IM'
251
251
  @p1.fed.should == 'IRL'
252
- @p1.fide.should == 2500035
252
+ @p1.fide_id.should == 2500035
253
253
  end
254
254
 
255
255
  it "should have a kind of symmetry" do
@@ -8,7 +8,7 @@ module ICU
8
8
  p = @t.player(num)
9
9
  p.first_name.should == first
10
10
  p.last_name.should == last
11
- [:gender, :title, :rating, :fide_rating, :fed, :id, :fide, :dob, :rank].each do |key|
11
+ [:gender, :title, :rating, :fide_rating, :fed, :id, :fide_id, :dob, :rank].each do |key|
12
12
  p.send(key).should == other[key] if other.has_key?(key)
13
13
  end
14
14
  end
@@ -71,9 +71,9 @@ KRAUSE
71
71
 
72
72
  it "should have players and their details" do
73
73
  @t.should have(3).players
74
- check_player(1, 'Gearoidin', 'Ui Laighleis', :gender => 'F', :fide_rating => 1985, :fed => 'IRL', :fide => 2501171, :dob => '1964-06-10', :rank => 2)
75
- check_player(2, 'Mark', 'Orr', :gender => 'M', :fide_rating => 2258, :fed => 'IRL', :fide => 2500035, :dob => '1955-11-09', :rank => 1, :title => 'IM')
76
- check_player(3, 'Viktor', 'Bologan', :gender => 'M', :fide_rating => 2663, :fed => 'MDA', :fide => 13900048, :dob => '1971-01-01', :rank => 3, :title => 'GM')
74
+ check_player(1, 'Gearoidin', 'Ui Laighleis', :gender => 'F', :fide_rating => 1985, :fed => 'IRL', :fide_id => 2501171, :dob => '1964-06-10', :rank => 2)
75
+ check_player(2, 'Mark', 'Orr', :gender => 'M', :fide_rating => 2258, :fed => 'IRL', :fide_id => 2500035, :dob => '1955-11-09', :rank => 1, :title => 'IM')
76
+ check_player(3, 'Viktor', 'Bologan', :gender => 'M', :fide_rating => 2663, :fed => 'MDA', :fide_id => 13900048, :dob => '1971-01-01', :rank => 3, :title => 'GM')
77
77
  end
78
78
 
79
79
  it "should have correct results for each player" do
@@ -254,9 +254,9 @@ KRAUSE
254
254
 
255
255
  it "should have local IDs by default" do
256
256
  @t = @p.parse(@krause)
257
- check_player(1, 'Gearoidin', 'Ui Laighleis', :id => 2501171, :fide => nil)
258
- check_player(2, 'Mark', 'Orr', :id => 2500035, :fide => nil)
259
- check_player(3, 'Viktor', 'Bologan', :id => nil, :fide => nil)
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)
260
260
  end
261
261
 
262
262
  it "should have FIDE IDs if option is used" do
@@ -11,7 +11,7 @@ module ICU
11
11
  class Player
12
12
  def sp_signature
13
13
  [
14
- name, id, fide, rating, fide_rating, points, rank,
14
+ name, id, fide_id, rating, fide_rating, points, rank,
15
15
  results.map{ |r| r.round }.join(''),
16
16
  results.map{ |r| r.score }.join(''),
17
17
  results.map{ |r| r.colour || "-" }.join(''),
@@ -70,9 +70,9 @@ EXPORT
70
70
  end
71
71
 
72
72
  it "players should have correct FIDE IDs" do
73
- @t.player(1).fide.should be_nil
74
- @t.player(2).fide.should == 1234568
75
- @t.player(3).fide.should == 1234567
73
+ @t.player(1).fide_id.should be_nil
74
+ @t.player(2).fide_id.should == 1234568
75
+ @t.player(3).fide_id.should == 1234567
76
76
  end
77
77
 
78
78
  it "players should have correct ICU ratings" do
@@ -125,7 +125,7 @@ EXPORT
125
125
  @t = ICU::Tournament.new(name, start)
126
126
  @t.add_player(ICU::Player.new('Bobby', 'Fischer', 10))
127
127
  @t.add_player(ICU::Player.new('Garry', 'Kasparov', 20))
128
- @t.add_player(ICU::Player.new('Mark', 'Orr', 30, :id => 1350, :fide => 2500035, :fed => 'IRL', :rating => 2200, :fide_rating => 2250))
128
+ @t.add_player(ICU::Player.new('Mark', 'Orr', 30, :id => 1350, :fide_id => 2500035, :fed => 'IRL', :rating => 2200, :fide_rating => 2250))
129
129
  @t.add_result(ICU::Result.new(1, 10, 'D', :opponent => 30))
130
130
  @t.add_result(ICU::Result.new(2, 20, 'W', :opponent => 30))
131
131
  @t.add_result(ICU::Result.new(3, 20, 'L', :opponent => 10))
@@ -156,11 +156,11 @@ EXPORT
156
156
  @x.should match(/^No\s*Name\s*Loc Id\s*Total\s*1\s*2\s*3\s*/)
157
157
  @x = @t.serialize('SPExport', :columns => [:points, :id, :fed])
158
158
  @x.should match(/^No\s*Name\s*Feder\s*Loc Id\s*Total\s*1\s*2\s*3\s*/)
159
- @x = @t.serialize('SPExport', :columns => [:points, :id, :fed, :fed, :rubbish, :fide])
159
+ @x = @t.serialize('SPExport', :columns => [:points, :id, :fed, :fed, :rubbish, :fide_id])
160
160
  @x.should match(/^No\s*Name\s*Feder\s*Intl Id\s*Loc Id\s*Total\s*1\s*2\s*3\s*/)
161
- @x = @t.serialize('SPExport', :columns => [:fed, :fide, :points, :id, :rating])
161
+ @x = @t.serialize('SPExport', :columns => [:fed, :fide_id, :points, :id, :rating])
162
162
  @x.should match(/^No\s*Name\s*Feder\s*Intl Id\s*Loc Id\s*Loc\s*Total\s*1\s*2\s*3\s*/)
163
- @x = @t.serialize('SPExport', :columns => [:fed, :fide, :fide_rating, :points, :id, :rating])
163
+ @x = @t.serialize('SPExport', :columns => [:fed, :fide_id, :fide_rating, :points, :id, :rating])
164
164
  @x.should match(/^No\s*Name\s*Feder\s*Intl Id\s*Loc Id\s*Rtg\s*Loc\s*Total\s*1\s*2\s*3\s*/)
165
165
  @x.should match(/3\s*Orr,\s*Mark\s*IRL\s*2500035\s*1350\s*2250\s*2200\s*0.5\s*1:D\s*2:L\s*:\s*/)
166
166
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 3
8
- - 1
9
- version: 1.3.1
8
+ - 2
9
+ version: 1.3.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark Orr