icu_tournament 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/icu_tournament/player.rb +23 -2
- data/lib/icu_tournament/tournament_krause.rb +4 -2
- data/lib/icu_tournament/tournament_spx.rb +1 -0
- data/lib/icu_tournament/version.rb +1 -1
- data/spec/player_spec.rb +13 -1
- data/spec/tournament_fcsv_spec.rb +6 -0
- data/spec/tournament_krause_spec.rb +23 -0
- data/spec/tournament_sp_spec.rb +5 -0
- data/spec/tournament_spx_spec.rb +27 -1
- metadata +5 -5
@@ -3,13 +3,28 @@ module ICU
|
|
3
3
|
# A player in a tournament must have a first name, a last name and a number
|
4
4
|
# which is unique in the tournament but otherwise arbitary.
|
5
5
|
#
|
6
|
-
# bobby = ICU::Player.new('robert
|
6
|
+
# bobby = ICU::Player.new(' robert j ', 'fischer', 17)
|
7
7
|
#
|
8
8
|
# Names are automatically cannonicalised (tidied up).
|
9
9
|
#
|
10
10
|
# bobby.first_name # => 'Robert J.'
|
11
11
|
# bobby.last_name # => 'Fischer'
|
12
12
|
#
|
13
|
+
# But the original untidied (other than white space cleanup and the addition of a comma
|
14
|
+
# to separate last name from first name) is avaiable from the _original_name_ method:
|
15
|
+
#
|
16
|
+
# bobby.original_name # => "fischer, robert j"
|
17
|
+
#
|
18
|
+
# This original name, set via the constructor, is unchanged by subsequent calls to
|
19
|
+
# the setter methods _first_name_ or _last_name.
|
20
|
+
#
|
21
|
+
# booby.first_name = 'Robert James'
|
22
|
+
# bobby.original_name # => "fischer, robert j"
|
23
|
+
#
|
24
|
+
# You can reset _orignal_name_, if necessary, and this does not affect either _first_name_ or _last_name_.
|
25
|
+
#
|
26
|
+
# bobby.original_name = "Fischer, Robert James"
|
27
|
+
#
|
13
28
|
# In addition, players have a number of optional attributes which can be specified
|
14
29
|
# via setters or in constructor hash options: _id_ (local or national ID), _fide_
|
15
30
|
# (FIDE ID), _fed_ (federation), _title_, _rating_ (local rating), _fide_rating,
|
@@ -87,12 +102,13 @@ module ICU
|
|
87
102
|
attr_positive_or_nil :id, :fide_id, :rating, :fide_rating, :rank
|
88
103
|
attr_date_or_nil :dob
|
89
104
|
|
90
|
-
attr_reader :results, :first_name, :last_name, :fed, :title, :gender
|
105
|
+
attr_reader :results, :first_name, :last_name, :original_name, :fed, :title, :gender
|
91
106
|
|
92
107
|
# Constructor. Must supply both names and a unique number for the tournament.
|
93
108
|
def initialize(first_name, last_name, num, opt={})
|
94
109
|
self.first_name = first_name
|
95
110
|
self.last_name = last_name
|
111
|
+
@original_name = Name.new(first_name, last_name).original
|
96
112
|
self.num = num
|
97
113
|
[:id, :fide_id, :fed, :title, :rating, :fide_rating, :rank, :dob, :gender].each do |atr|
|
98
114
|
self.send("#{atr}=", opt[atr]) unless opt[atr].nil?
|
@@ -114,6 +130,11 @@ module ICU
|
|
114
130
|
@last_name = name.last
|
115
131
|
end
|
116
132
|
|
133
|
+
# Reset the original name.
|
134
|
+
def original_name=(original_name)
|
135
|
+
@original_name = ICU::Util.to_utf8(original_name)
|
136
|
+
end
|
137
|
+
|
117
138
|
# Return the full name, last name first.
|
118
139
|
def name
|
119
140
|
"#{last_name}, #{first_name}"
|
@@ -261,7 +261,9 @@ module ICU
|
|
261
261
|
|
262
262
|
# Player details.
|
263
263
|
num = @data[0, 4]
|
264
|
-
nam =
|
264
|
+
nam = @data[10, 32]
|
265
|
+
nams = nam.split(/,/)
|
266
|
+
raise "missing comma in name #{nam.trim}" unless nams.size > 1
|
265
267
|
opt =
|
266
268
|
{
|
267
269
|
:gender => @data[5, 1],
|
@@ -272,7 +274,7 @@ module ICU
|
|
272
274
|
}
|
273
275
|
opt[arg[:fide] ? :fide_id : :id] = @data[53, 11]
|
274
276
|
opt[arg[:fide] ? :fide_rating : :rating] = @data[44, 4]
|
275
|
-
player = Player.new(
|
277
|
+
player = Player.new(nams.last, nams.first, num, opt)
|
276
278
|
@tournament.add_player(player)
|
277
279
|
|
278
280
|
# Results.
|
data/spec/player_spec.rb
CHANGED
@@ -18,6 +18,7 @@ module ICU
|
|
18
18
|
p = Player.new('Mark', 'Orr', 1)
|
19
19
|
p.first_name.should == 'Mark'
|
20
20
|
p.last_name.should == 'Orr'
|
21
|
+
p.original_name.should == 'Orr, Mark'
|
21
22
|
end
|
22
23
|
|
23
24
|
it "should be resettable via accessors" do
|
@@ -26,6 +27,7 @@ module ICU
|
|
26
27
|
p.last_name= 'Kasparov'
|
27
28
|
p.first_name.should == 'Gary'
|
28
29
|
p.last_name.should == 'Kasparov'
|
30
|
+
p.original_name.should == 'Orr, Mark'
|
29
31
|
end
|
30
32
|
|
31
33
|
it "should not contain invalid characters" do
|
@@ -33,7 +35,7 @@ module ICU
|
|
33
35
|
lambda { Player.new('Mark', '*!', 1) }.should raise_error(/invalid last name/)
|
34
36
|
end
|
35
37
|
|
36
|
-
it "should not have empty last name" do
|
38
|
+
it "should not have empty last name or first name" do
|
37
39
|
lambda { Player.new('Mark', '', 1) }.should raise_error(/invalid last name/)
|
38
40
|
lambda { Player.new('', 'Orr', 1) }.should raise_error(/invalid first name/)
|
39
41
|
end
|
@@ -50,6 +52,16 @@ module ICU
|
|
50
52
|
p.name.should == 'Orr, Z.'
|
51
53
|
p.last_name = " o meFiSto "
|
52
54
|
p.name.should == "O'Mefisto, Z."
|
55
|
+
p.original_name.should == 'ORR, maRk J l'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "the original name is resetable" do
|
59
|
+
p = Player.new('Mark', 'Orr', 1)
|
60
|
+
p.name.should == 'Orr, Mark'
|
61
|
+
p.original_name.should == 'Orr, Mark'
|
62
|
+
p.original_name = 'Cronin, April'
|
63
|
+
p.name.should == 'Orr, Mark'
|
64
|
+
p.original_name.should == 'Cronin, April'
|
53
65
|
end
|
54
66
|
end
|
55
67
|
|
@@ -237,6 +237,12 @@ CSV
|
|
237
237
|
check_player(2, 'Gary', 'Kasparov', 1, 0, 0.5, :fide_rating => 2800, :fed => 'RUS', :title => 'GM')
|
238
238
|
check_player(3, 'Mark', 'Orr', 1, 0, 0.5, :fide_rating => 2100, :fed => 'IRL', :title => 'IM')
|
239
239
|
end
|
240
|
+
|
241
|
+
it "should still have original names" do
|
242
|
+
@t.player(1).original_name.should == "ui Laighleis, gearoidin"
|
243
|
+
@t.player(2).original_name.should == "kasparov, gary"
|
244
|
+
@t.player(3).original_name.should == "Orr, Mark"
|
245
|
+
end
|
240
246
|
end
|
241
247
|
|
242
248
|
context "#parse" do
|
@@ -441,6 +441,29 @@ KRAUSE
|
|
441
441
|
@t.name.should == "Läs Végas National Opeñ"
|
442
442
|
end
|
443
443
|
end
|
444
|
+
|
445
|
+
context "preserving original names" do
|
446
|
+
before(:all) do
|
447
|
+
@k = <<KRAUSE
|
448
|
+
012 Las Vegas National Open
|
449
|
+
042 2008-06-07
|
450
|
+
001 1 w ui laighleis,GEAROIDIN 1.0 2 b 0 3 w 1
|
451
|
+
001 2 m m ORR, mark 2.0 1 w 1 3 b 1
|
452
|
+
001 3 m g BOLOGAN,VIKTOR 0.0 1 b 0 2 w 0
|
453
|
+
KRAUSE
|
454
|
+
@p = ICU::Tournament::Krause.new
|
455
|
+
end
|
456
|
+
|
457
|
+
it "should canonicalise names but also preserve originals" do
|
458
|
+
@t = @p.parse!(@k)
|
459
|
+
check_player(1, 'Gearoidin', 'Ui Laighleis')
|
460
|
+
check_player(2, 'Mark', 'Orr')
|
461
|
+
check_player(3, 'Viktor', 'Bologan')
|
462
|
+
@t.player(1).original_name.should == "ui laighleis, GEAROIDIN"
|
463
|
+
@t.player(2).original_name.should == "ORR, mark"
|
464
|
+
@t.player(3).original_name.should == "BOLOGAN, VIKTOR"
|
465
|
+
end
|
466
|
+
end
|
444
467
|
|
445
468
|
context "parsing files" do
|
446
469
|
before(:each) do
|
data/spec/tournament_sp_spec.rb
CHANGED
@@ -44,6 +44,11 @@ module ICU
|
|
44
44
|
@t.player(56).sp_signature.should == "McDonnell, Cathal|||498||0.0|54|1|L|-|F" # last
|
45
45
|
end
|
46
46
|
|
47
|
+
it "original names should be preserved" do
|
48
|
+
@t.player(2).original_name.should == "MULLOOLY, neil m"
|
49
|
+
@t.player(4).original_name.should == "Gallagher, Mark"
|
50
|
+
end
|
51
|
+
|
47
52
|
it "should have consistent ranks" do
|
48
53
|
@t.players.map{ |p| p.rank }.sort.join('').should == (1..@t.players.size).to_a.join('')
|
49
54
|
end
|
data/spec/tournament_spx_spec.rb
CHANGED
@@ -186,7 +186,7 @@ EXPORT
|
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
-
context "invisible bonuses
|
189
|
+
context "extreme invisible bonuses example" do
|
190
190
|
before(:each) do
|
191
191
|
@x = <<EXPORT
|
192
192
|
No Name Total 1 2 3
|
@@ -206,6 +206,32 @@ EXPORT
|
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
209
|
+
context "preservation of original names" do
|
210
|
+
before(:each) do
|
211
|
+
@x = <<EXPORT
|
212
|
+
No Name Total 1 2 3
|
213
|
+
|
214
|
+
1 daffy duck 2.0 0: 3:W 2:D
|
215
|
+
2 MOUSE, minerva 1.5 3:D 0: 1:D
|
216
|
+
3 mouse, MICKEY 1.0 2:D 1:L 0:D
|
217
|
+
EXPORT
|
218
|
+
@p = ICU::Tournament::SPExport.new
|
219
|
+
@t = @p.parse!(@x, :name => "Mickey Mouse Masters", :start => "2012-01-01")
|
220
|
+
end
|
221
|
+
|
222
|
+
it "players should have canonicalised names" do
|
223
|
+
@t.player(1).name.should == 'Duck, Daffy'
|
224
|
+
@t.player(2).name.should == 'Mouse, Minerva'
|
225
|
+
@t.player(3).name.should == 'Mouse, Mickey'
|
226
|
+
end
|
227
|
+
|
228
|
+
it "players should have original names" do
|
229
|
+
@t.player(1).original_name.should == 'daffy duck'
|
230
|
+
@t.player(2).original_name.should == 'MOUSE, minerva'
|
231
|
+
@t.player(3).original_name.should == 'mouse, MICKEY'
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
209
235
|
context "odds and ends" do
|
210
236
|
before(:each) do
|
211
237
|
@x = <<EXPORT
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 1.3.
|
8
|
+
- 5
|
9
|
+
version: 1.3.5
|
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-02-
|
17
|
+
date: 2011-02-19 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -58,8 +58,8 @@ dependencies:
|
|
58
58
|
segments:
|
59
59
|
- 0
|
60
60
|
- 1
|
61
|
-
-
|
62
|
-
version: 0.1.
|
61
|
+
- 3
|
62
|
+
version: 0.1.3
|
63
63
|
type: :runtime
|
64
64
|
version_requirements: *id003
|
65
65
|
- !ruby/object:Gem::Dependency
|