icu_tournament 0.8.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/LICENCE +22 -0
- data/README.rdoc +75 -0
- data/Rakefile +57 -0
- data/VERSION.yml +5 -0
- data/lib/icu_tournament.rb +8 -0
- data/lib/icu_tournament/federation.rb +303 -0
- data/lib/icu_tournament/name.rb +274 -0
- data/lib/icu_tournament/player.rb +204 -0
- data/lib/icu_tournament/result.rb +191 -0
- data/lib/icu_tournament/team.rb +90 -0
- data/lib/icu_tournament/tournament.rb +508 -0
- data/lib/icu_tournament/tournament_fcsv.rb +310 -0
- data/lib/icu_tournament/tournament_krause.rb +329 -0
- data/lib/icu_tournament/util.rb +156 -0
- data/spec/federation_spec.rb +176 -0
- data/spec/name_spec.rb +208 -0
- data/spec/player_spec.rb +313 -0
- data/spec/result_spec.rb +203 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/team_spec.rb +60 -0
- data/spec/tournament_fcsv_spec.rb +548 -0
- data/spec/tournament_krause_spec.rb +379 -0
- data/spec/tournament_spec.rb +733 -0
- data/spec/util_spec.rb +357 -0
- metadata +97 -0
data/spec/util_spec.rb
ADDED
@@ -0,0 +1,357 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
module ICU
|
4
|
+
describe Util do
|
5
|
+
context "#parsedate" do
|
6
|
+
it "should parse standard dates" do
|
7
|
+
Util.parsedate('2001-01-01').should == '2001-01-01'
|
8
|
+
Util.parsedate('1955-11-09').should == '1955-11-09'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should handle US format" do
|
12
|
+
Util.parsedate('03/30/2009').should == '2009-03-30'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should handle European format" do
|
16
|
+
Util.parsedate('30/03/2009').should == '2009-03-30'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should prefer European format" do
|
20
|
+
Util.parsedate('02/03/2009').should == '2009-03-02'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should handle US style when there's no alternative" do
|
24
|
+
Util.parsedate('02/23/2009').should == '2009-02-23'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should handle single digits" do
|
28
|
+
Util.parsedate('9/8/2006').should == '2006-08-09'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should handle names of monthsx" do
|
32
|
+
Util.parsedate('9th Nov 1955').should == '1955-11-09'
|
33
|
+
Util.parsedate('16th June 1986').should == '1986-06-16'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe Accessor do
|
39
|
+
context "#attr_accessor" do
|
40
|
+
before(:each) do
|
41
|
+
@class = Class.new
|
42
|
+
@class.extend ICU::Accessor
|
43
|
+
@obj = @class.new
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not have an accessor unless declared" do
|
47
|
+
@obj.respond_to?(:myatr).should be_false
|
48
|
+
@obj.respond_to?(:myatr=).should be_false
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should have a getter but no setter with the default declaration" do
|
52
|
+
@class.attr_accessor('myatr')
|
53
|
+
@obj.respond_to?(:myatr).should be_true
|
54
|
+
@obj.respond_to?(:myatr=).should be_false
|
55
|
+
@obj.instance_eval { @myatr = 42 }
|
56
|
+
@obj.myatr.should == 42
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should be able to create do-it-yourself setters such as for a positive integer" do
|
60
|
+
@class.attr_accessor('myatr') do |val|
|
61
|
+
tmp = val.to_i
|
62
|
+
raise "invalid positive integer (#{val})" unless tmp > 0
|
63
|
+
tmp
|
64
|
+
end
|
65
|
+
@obj.respond_to?(:myatr).should be_true
|
66
|
+
@obj.respond_to?(:myatr=).should be_true
|
67
|
+
lambda { @obj.myatr = "no number here" }.should raise_error(/invalid positive integer \(no number here\)/)
|
68
|
+
lambda { @obj.myatr = -1 }.should raise_error
|
69
|
+
lambda { @obj.myatr = 0 }.should raise_error
|
70
|
+
lambda { @obj.myatr = 1 }.should_not raise_error
|
71
|
+
@obj.myatr.should == 1
|
72
|
+
lambda { @obj.myatr = '42' }.should_not raise_error
|
73
|
+
@obj.myatr.should == 42
|
74
|
+
lambda { @obj.myatr = ' 0371 ' }.should_not raise_error
|
75
|
+
@obj.myatr.should == 371
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "#attr_integer" do
|
80
|
+
before(:each) do
|
81
|
+
@class = Class.new
|
82
|
+
@class.extend ICU::Accessor
|
83
|
+
@class.attr_integer :myint
|
84
|
+
@obj = @class.new
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should have a getter and setter" do
|
88
|
+
@obj.respond_to?(:myint).should be_true
|
89
|
+
@obj.respond_to?(:myint=).should be_true
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should work with ints" do
|
93
|
+
@obj.myint = -43
|
94
|
+
@obj.myint.should == -43
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should work with strings" do
|
98
|
+
@obj.myint = " -99 "
|
99
|
+
@obj.myint.should == -99
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should handle zero" do
|
103
|
+
lambda { @obj.myint = 0 }.should_not raise_error
|
104
|
+
lambda { @obj.myint = '0' }.should_not raise_error
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should reject nil and other non-numbers" do
|
108
|
+
lambda { @obj.myint = nil }.should raise_error(/invalid/)
|
109
|
+
lambda { @obj.myint = "N" }.should raise_error(/invalid/)
|
110
|
+
lambda { @obj.myint = " " }.should raise_error(/invalid/)
|
111
|
+
lambda { @obj.myint = '' }.should raise_error(/invalid/)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should handle multiple names" do
|
115
|
+
@class.attr_integer :yourint, :hisint
|
116
|
+
@obj.respond_to?(:yourint).should be_true
|
117
|
+
@obj.respond_to?(:hisint=).should be_true
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "#attr_integer_or_nil" do
|
122
|
+
before(:each) do
|
123
|
+
@class = Class.new
|
124
|
+
@class.extend ICU::Accessor
|
125
|
+
@class.attr_integer_or_nil :myint
|
126
|
+
@obj = @class.new
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should have a getter and setter" do
|
130
|
+
@obj.respond_to?(:myint).should be_true
|
131
|
+
@obj.respond_to?(:myint=).should be_true
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should work with ints and nil and spaces" do
|
135
|
+
@obj.myint = 43
|
136
|
+
@obj.myint.should == 43
|
137
|
+
@obj.myint = nil
|
138
|
+
@obj.myint.should == nil
|
139
|
+
@obj.myint = ' '
|
140
|
+
@obj.myint.should == nil
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should reject non-numbers" do
|
144
|
+
lambda { @obj.myint = "N" }.should raise_error(/invalid/)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should handle multiple names" do
|
148
|
+
@class.attr_integer :yourint, :hisint
|
149
|
+
@obj.respond_to?(:yourint).should be_true
|
150
|
+
@obj.respond_to?(:hisint=).should be_true
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "#attr_positive" do
|
155
|
+
before(:each) do
|
156
|
+
@class = Class.new
|
157
|
+
@class.extend ICU::Accessor
|
158
|
+
@class.attr_positive :mypos
|
159
|
+
@obj = @class.new
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should have a getter and setter" do
|
163
|
+
@obj.respond_to?(:mypos).should be_true
|
164
|
+
@obj.respond_to?(:mypos=).should be_true
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should work as expected" do
|
168
|
+
@obj.mypos = "34"
|
169
|
+
@obj.mypos.should == 34
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should reject nil and other non-positive integers" do
|
173
|
+
lambda { @obj.mypos = nil }.should raise_error(/invalid/)
|
174
|
+
lambda { @obj.mypos = 'X' }.should raise_error(/invalid/)
|
175
|
+
lambda { @obj.mypos = '0' }.should raise_error(/invalid/)
|
176
|
+
lambda { @obj.mypos = -13 }.should raise_error(/invalid/)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should handle multiple names" do
|
180
|
+
@class.attr_integer :ourpos, :theirpos
|
181
|
+
@obj.respond_to?(:ourpos).should be_true
|
182
|
+
@obj.respond_to?(:theirpos=).should be_true
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
context "#attr_positive_or_nil" do
|
187
|
+
before(:each) do
|
188
|
+
@class = Class.new
|
189
|
+
@class.extend ICU::Accessor
|
190
|
+
@class.attr_positive_or_nil :mypon
|
191
|
+
@obj = @class.new
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should have a getter and setter" do
|
195
|
+
@obj.respond_to?(:mypon).should be_true
|
196
|
+
@obj.respond_to?(:mypon=).should be_true
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should work with numbers, nil, empty strings and spaces" do
|
200
|
+
@obj.mypon = " 54 "
|
201
|
+
@obj.mypon.should == 54
|
202
|
+
@obj.mypon = nil
|
203
|
+
@obj.mypon.should be_nil
|
204
|
+
@obj.mypon = ''
|
205
|
+
@obj.mypon.should be_nil
|
206
|
+
@obj.mypon = ' '
|
207
|
+
@obj.mypon.should be_nil
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should reject non-integers and non-positive integers" do
|
211
|
+
lambda { @obj.mypon = 'X' }.should raise_error(/invalid/)
|
212
|
+
lambda { @obj.mypon = '0' }.should raise_error(/invalid/)
|
213
|
+
lambda { @obj.mypon = -13 }.should raise_error(/invalid/)
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should handle multiple names" do
|
217
|
+
@class.attr_integer :ourpon, :theirpon
|
218
|
+
@obj.respond_to?(:ourpon).should be_true
|
219
|
+
@obj.respond_to?(:theirpon=).should be_true
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context "#attr_date" do
|
224
|
+
before(:each) do
|
225
|
+
@class = Class.new
|
226
|
+
@class.extend ICU::Accessor
|
227
|
+
@class.attr_date :mydate
|
228
|
+
@obj = @class.new
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should have a getter and setter" do
|
232
|
+
@obj.respond_to?(:mydate).should be_true
|
233
|
+
@obj.respond_to?(:mydate=).should be_true
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should work as expected" do
|
237
|
+
@obj.mydate = "2009/11/09"
|
238
|
+
@obj.mydate.should == '2009-11-09'
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should reject nil and other non-dates" do
|
242
|
+
lambda { @obj.mydate = nil }.should raise_error(/invalid/)
|
243
|
+
lambda { @obj.mydate = 'blah de blah' }.should raise_error(/invalid/)
|
244
|
+
lambda { @obj.mydate = ' ' }.should raise_error(/invalid/)
|
245
|
+
lambda { @obj.mydate = 0 }.should raise_error(/invalid/)
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should handle multiple names" do
|
249
|
+
@class.attr_date :ourdate, :theirdate
|
250
|
+
@obj.respond_to?(:ourdate).should be_true
|
251
|
+
@obj.respond_to?(:theirdate=).should be_true
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
context "#attr_date_or_nil" do
|
256
|
+
before(:each) do
|
257
|
+
@class = Class.new
|
258
|
+
@class.extend ICU::Accessor
|
259
|
+
@class.attr_date_or_nil :mydate
|
260
|
+
@obj = @class.new
|
261
|
+
end
|
262
|
+
|
263
|
+
it "should have a getter and setter" do
|
264
|
+
@obj.respond_to?(:mydate).should be_true
|
265
|
+
@obj.respond_to?(:mydate=).should be_true
|
266
|
+
end
|
267
|
+
|
268
|
+
it "should work as expected, including with nil" do
|
269
|
+
@obj.mydate = "2009/11/09"
|
270
|
+
@obj.mydate.should == '2009-11-09'
|
271
|
+
@obj.mydate = nil
|
272
|
+
@obj.mydate.should be_nil
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should reject non-dates" do
|
276
|
+
lambda { @obj.mydate = 'blah de blah' }.should raise_error(/invalid/)
|
277
|
+
lambda { @obj.mydate = 0 }.should raise_error(/invalid/)
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should handle multiple names" do
|
281
|
+
@class.attr_date :ourdate, :theirdate
|
282
|
+
@obj.respond_to?(:ourdate).should be_true
|
283
|
+
@obj.respond_to?(:theirdate=).should be_true
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
context "#attr_string" do
|
288
|
+
before(:each) do
|
289
|
+
@class = Class.new
|
290
|
+
@class.extend ICU::Accessor
|
291
|
+
@class.attr_string %r%[a-z]+%i, :mystring
|
292
|
+
@obj = @class.new
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should have a getter and setter" do
|
296
|
+
@obj.respond_to?(:mystring).should be_true
|
297
|
+
@obj.respond_to?(:mystring=).should be_true
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should work as expected" do
|
301
|
+
@obj.mystring = " mark "
|
302
|
+
@obj.mystring.should == 'mark'
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should reject values that don't match" do
|
306
|
+
lambda { @obj.mystring = nil }.should raise_error(/invalid/)
|
307
|
+
lambda { @obj.mystring = ' 123 ' }.should raise_error(/invalid/)
|
308
|
+
lambda { @obj.mystring = ' ' }.should raise_error(/invalid/)
|
309
|
+
lambda { @obj.mystring = 0 }.should raise_error(/invalid/)
|
310
|
+
lambda { @obj.mystring = ' a ' }.should_not raise_error
|
311
|
+
lambda { @obj.mystring = 'ZYX' }.should_not raise_error
|
312
|
+
end
|
313
|
+
|
314
|
+
it "should handle multiple names" do
|
315
|
+
@class.attr_string %r%^[A-Z]{3}$%, :ourstring, :theirstring
|
316
|
+
@obj.respond_to?(:ourstring=).should be_true
|
317
|
+
@obj.respond_to?(:theirstring).should be_true
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
context "#attr_string_or_nil" do
|
322
|
+
before(:each) do
|
323
|
+
@class = Class.new
|
324
|
+
@class.extend ICU::Accessor
|
325
|
+
@class.attr_string_or_nil %r%^[1-9]\d*$%i, :mystring
|
326
|
+
@obj = @class.new
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should have a getter and setter" do
|
330
|
+
@obj.respond_to?(:mystring).should be_true
|
331
|
+
@obj.respond_to?(:mystring=).should be_true
|
332
|
+
end
|
333
|
+
|
334
|
+
it "should work as expected" do
|
335
|
+
@obj.mystring = " 12345 "
|
336
|
+
@obj.mystring.should == '12345'
|
337
|
+
@obj.mystring = nil
|
338
|
+
@obj.mystring.should be_nil
|
339
|
+
@obj.mystring = ' '
|
340
|
+
@obj.mystring.should be_nil
|
341
|
+
end
|
342
|
+
|
343
|
+
it "should reject values that don't match" do
|
344
|
+
lambda { @obj.mystring = ' 0 ' }.should raise_error(/invalid/)
|
345
|
+
lambda { @obj.mystring = 0 }.should raise_error(/invalid/)
|
346
|
+
lambda { @obj.mystring = -1 }.should raise_error(/invalid/)
|
347
|
+
lambda { @obj.mystring = 98 }.should_not raise_error
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should handle multiple names" do
|
351
|
+
@class.attr_string %r%^[A-Z][a-z]+%, :ourstring, :theirstring
|
352
|
+
@obj.respond_to?(:ourstring=).should be_true
|
353
|
+
@obj.respond_to?(:theirstring).should be_true
|
354
|
+
end
|
355
|
+
end
|
356
|
+
end
|
357
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: icu_tournament
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Orr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-01 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: fastercsv
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.4.0
|
24
|
+
version:
|
25
|
+
description: Convert files of chess tournament data in different formats to ruby classes and vice-versa.
|
26
|
+
email: mark.j.l.orr@googlemail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- LICENCE
|
36
|
+
- README.rdoc
|
37
|
+
- Rakefile
|
38
|
+
- VERSION.yml
|
39
|
+
- lib/icu_tournament.rb
|
40
|
+
- lib/icu_tournament/federation.rb
|
41
|
+
- lib/icu_tournament/name.rb
|
42
|
+
- lib/icu_tournament/player.rb
|
43
|
+
- lib/icu_tournament/result.rb
|
44
|
+
- lib/icu_tournament/team.rb
|
45
|
+
- lib/icu_tournament/tournament.rb
|
46
|
+
- lib/icu_tournament/tournament_fcsv.rb
|
47
|
+
- lib/icu_tournament/tournament_krause.rb
|
48
|
+
- lib/icu_tournament/util.rb
|
49
|
+
- spec/federation_spec.rb
|
50
|
+
- spec/name_spec.rb
|
51
|
+
- spec/player_spec.rb
|
52
|
+
- spec/result_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
- spec/team_spec.rb
|
55
|
+
- spec/tournament_fcsv_spec.rb
|
56
|
+
- spec/tournament_krause_spec.rb
|
57
|
+
- spec/tournament_spec.rb
|
58
|
+
- spec/util_spec.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/sanichi/icu_tournament
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --charset=UTF-8
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.3.5
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: For reading and writing files of chess tournament data.
|
87
|
+
test_files:
|
88
|
+
- spec/federation_spec.rb
|
89
|
+
- spec/name_spec.rb
|
90
|
+
- spec/player_spec.rb
|
91
|
+
- spec/result_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/team_spec.rb
|
94
|
+
- spec/tournament_fcsv_spec.rb
|
95
|
+
- spec/tournament_krause_spec.rb
|
96
|
+
- spec/tournament_spec.rb
|
97
|
+
- spec/util_spec.rb
|