icu_tournament 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/icu_tournament/tournament_sp.rb +13 -1
- data/lib/icu_tournament/version.rb +1 -1
- data/spec/tournament_sp_spec.rb +30 -3
- metadata +3 -3
@@ -50,10 +50,18 @@ ratings or IDs are required instead, use the options _id_ and _rating_. For exam
|
|
50
50
|
tournament.player(2).id # => 12379 (ICU ID)
|
51
51
|
tournament.player(2).rating # => 2556 (ICU rating)
|
52
52
|
|
53
|
-
tournament = parser.parse_file('ncc', :start => '2010-05-08', :id =>
|
53
|
+
tournament = parser.parse_file('ncc', :start => '2010-05-08', :id => 'intl', :rating => 'intl')
|
54
54
|
tournament.player(2).id # => 1205064 (FIDE ID)
|
55
55
|
tournament.player(2).rating # => 2530 (FIDE rating)
|
56
56
|
|
57
|
+
By default, the parse will fail completely if the ".trn" file contains any invalid federations (see ICU::Federation).
|
58
|
+
There are two alternative behaviours controlled by setting the _fed_ option:
|
59
|
+
|
60
|
+
tournament = parser.parse_file('ncc', :start => '2010-05-08', :fed == 'skip') # => silently skips invalid federations
|
61
|
+
tournament = parser.parse_file('ncc', :start => '2010-05-08', :fed == 'ignore') # => ignores all federations
|
62
|
+
|
63
|
+
Note that federations that don't match 3 letters are always silently skipped.
|
64
|
+
|
57
65
|
Because the data is in three parts, some of which are in a legacy binary format, serialization to this format is
|
58
66
|
not supported. Instead, a method is provided to serialize any tournament type into the text export format of
|
59
67
|
<em>SwissPerfect</em>, an example of which is shown below.
|
@@ -277,6 +285,10 @@ See ICU::Tournament for more about tie-breaks.
|
|
277
285
|
when :rating then val = val.to_i > 0 ? val : nil
|
278
286
|
when :title then val = val.to_i > 0 ? %w(GM WGM IM WIM FM WFM)[val.to_i-1] : nil
|
279
287
|
end
|
288
|
+
if pair[0] == :fed && val && arg[:fed]
|
289
|
+
val = nil if arg[:fed].to_s == 'ignore'
|
290
|
+
val = nil if arg[:fed].to_s == 'skip' && !ICU::Federation.find(val)
|
291
|
+
end
|
280
292
|
hash[pair[0]] = val unless val.nil? || val == ''
|
281
293
|
hash
|
282
294
|
end
|
data/spec/tournament_sp_spec.rb
CHANGED
@@ -193,7 +193,7 @@ module ICU
|
|
193
193
|
end
|
194
194
|
|
195
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 =>
|
196
|
+
@t = @p.parse_file(SAMPLES + 'ncc', :start => "2010-05-08", :id => 'intl', :rating => :intl)
|
197
197
|
@t.player(2).signature.should == "Szabo, Gergely|1205064||4.0|4|1234|WWWW|WBWB|TTTT"
|
198
198
|
@t.player(5).signature.should == "Daly, Colm|2500434||3.5|7|1234|WWWD|WBWB|TTTT"
|
199
199
|
@t.player(8).signature.should == "Vega, Marcos Llaneza|2253585||3.0|16|1234|DDWW|BWBW|TTTT"
|
@@ -201,6 +201,33 @@ module ICU
|
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
|
+
context "Drogheda Section A, 2010, with an invalid federation" do
|
205
|
+
|
206
|
+
before(:each) do
|
207
|
+
@p = ICU::Tournament::SwissPerfect.new
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should not parse because of the invalid federation" do
|
211
|
+
t = @p.parse_file(SAMPLES + 'drog_a.zip', :start => "2010-06-04")
|
212
|
+
t.should be_nil
|
213
|
+
@p.error.should match(/invalid federation/i)
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should parse if instructed to skip bad feds" do
|
217
|
+
t = @p.parse_file(SAMPLES + 'drog_a.zip', :start => "2010-06-04", :fed => :skip)
|
218
|
+
@p.error.should be_nil
|
219
|
+
t.player(5).fed.should be_nil
|
220
|
+
t.player(6).fed.should == "ESP"
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should parse if instructed to skip all feds" do
|
224
|
+
t = @p.parse_file(SAMPLES + 'drog_a.zip', :start => "2010-06-04", :fed => 'ignore')
|
225
|
+
@p.error.should be_nil
|
226
|
+
t.player(5).fed.should be_nil
|
227
|
+
t.player(6).fed.should be_nil
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
204
231
|
context "Non-existant ZIP file" do
|
205
232
|
|
206
233
|
before(:all) do
|
@@ -272,7 +299,7 @@ module ICU
|
|
272
299
|
@t.player(67).signature.should == "Lee, Shane|780|1633|1.0|52|134|DLD|WWW|TTT"
|
273
300
|
end
|
274
301
|
end
|
275
|
-
|
302
|
+
|
276
303
|
context "ZIP file without a ZIP ending" do
|
277
304
|
|
278
305
|
before(:all) do
|
@@ -287,7 +314,7 @@ module ICU
|
|
287
314
|
lambda { @p.parse_file!(SAMPLES + 'nccz.piz', :zip => true, :start => "2010-05-08") }.should_not raise_error
|
288
315
|
end
|
289
316
|
end
|
290
|
-
|
317
|
+
|
291
318
|
context "Defaulting the start date" do
|
292
319
|
|
293
320
|
before(:all) do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 11
|
9
|
+
version: 1.0.11
|
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-
|
17
|
+
date: 2010-09-12 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|