icu_tournament 1.7.3 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/icu_tournament/player.rb +2 -2
- data/lib/icu_tournament/result.rb +1 -1
- data/lib/icu_tournament/tournament.rb +2 -2
- data/lib/icu_tournament/tournament_fcsv.rb +2 -2
- data/lib/icu_tournament/tournament_krause.rb +2 -2
- data/lib/icu_tournament/tournament_sp.rb +1 -1
- data/lib/icu_tournament/tournament_spx.rb +2 -2
- data/lib/icu_tournament/util.rb +125 -124
- data/lib/icu_tournament/version.rb +1 -1
- data/spec/util_spec.rb +357 -353
- metadata +4 -4
@@ -97,7 +97,7 @@ module ICU
|
|
97
97
|
# fox1.gender # => 'M'
|
98
98
|
#
|
99
99
|
class Player
|
100
|
-
extend ICU::Accessor
|
100
|
+
extend ICU::Util::Accessor
|
101
101
|
attr_integer :num
|
102
102
|
attr_positive_or_nil :id, :fide_id, :rating, :fide_rating, :rank
|
103
103
|
attr_date_or_nil :dob
|
@@ -132,7 +132,7 @@ module ICU
|
|
132
132
|
|
133
133
|
# Reset the original name.
|
134
134
|
def original_name=(original_name)
|
135
|
-
@original_name = ICU::Util.to_utf8(original_name)
|
135
|
+
@original_name = ICU::Util::String.to_utf8(original_name)
|
136
136
|
end
|
137
137
|
|
138
138
|
# Return the full name, last name first.
|
@@ -193,7 +193,7 @@ module ICU
|
|
193
193
|
# in which case any options supplied to this method will be silently ignored.
|
194
194
|
#
|
195
195
|
class Tournament
|
196
|
-
extend ICU::Accessor
|
196
|
+
extend ICU::Util::Accessor
|
197
197
|
attr_date :start
|
198
198
|
attr_date_or_nil :finish
|
199
199
|
attr_positive_or_nil :rounds
|
@@ -224,7 +224,7 @@ module ICU
|
|
224
224
|
# Add a round date.
|
225
225
|
def add_round_date(round_date)
|
226
226
|
round_date = round_date.to_s.strip
|
227
|
-
parsed_date = Util.
|
227
|
+
parsed_date = Util::Date.parse(round_date)
|
228
228
|
raise "invalid round date (#{round_date})" unless parsed_date
|
229
229
|
@round_dates << parsed_date
|
230
230
|
end
|
@@ -125,7 +125,7 @@ module ICU
|
|
125
125
|
def parse!(csv, arg={})
|
126
126
|
@state, @line, @round, @sum, @error = 0, 0, nil, nil, nil
|
127
127
|
@tournament = Tournament.new('Unspecified', '2000-01-01')
|
128
|
-
csv = ICU::Util.to_utf8(csv) unless arg[:is_utf8]
|
128
|
+
csv = ICU::Util::String.to_utf8(csv) unless arg[:is_utf8]
|
129
129
|
|
130
130
|
CSV.parse(csv, :row_sep => :auto) do |r|
|
131
131
|
@line += 1 # increment line number
|
@@ -184,7 +184,7 @@ module ICU
|
|
184
184
|
|
185
185
|
# Same as <em>parse!</em> except the input is a file name rather than file contents.
|
186
186
|
def parse_file!(file)
|
187
|
-
csv = ICU::Util.read_utf8(file)
|
187
|
+
csv = ICU::Util::File.read_utf8(file)
|
188
188
|
parse!(csv, :is_utf8 => true)
|
189
189
|
end
|
190
190
|
|
@@ -216,7 +216,7 @@ module ICU
|
|
216
216
|
@name_set, @start_set = false, false
|
217
217
|
@comments = ''
|
218
218
|
@results = Array.new
|
219
|
-
krs = ICU::Util.to_utf8(krs) unless arg[:is_utf8]
|
219
|
+
krs = ICU::Util::String.to_utf8(krs) unless arg[:is_utf8]
|
220
220
|
lines = get_lines(krs)
|
221
221
|
|
222
222
|
# Process all lines.
|
@@ -292,7 +292,7 @@ module ICU
|
|
292
292
|
|
293
293
|
# Same as <em>parse!</em> except the input is a file name rather than file contents.
|
294
294
|
def parse_file!(file, arg={})
|
295
|
-
krause = ICU::Util.read_utf8(file)
|
295
|
+
krause = ICU::Util::File.read_utf8(file)
|
296
296
|
arg[:is_utf8] = true
|
297
297
|
parse!(krause, arg)
|
298
298
|
end
|
@@ -128,7 +128,7 @@ module ICU
|
|
128
128
|
@lineno = 0
|
129
129
|
@header = nil
|
130
130
|
@results = Array.new
|
131
|
-
spx = ICU::Util.to_utf8(spx) unless arg[:is_utf8]
|
131
|
+
spx = ICU::Util::String.to_utf8(spx) unless arg[:is_utf8]
|
132
132
|
|
133
133
|
# Process each line.
|
134
134
|
spx.each_line do |line|
|
@@ -172,7 +172,7 @@ module ICU
|
|
172
172
|
|
173
173
|
# Same as <em>parse!</em> except the input is a file name rather than file contents.
|
174
174
|
def parse_file!(file, arg={})
|
175
|
-
spx = ICU::Util.read_utf8(file)
|
175
|
+
spx = ICU::Util::File.read_utf8(file)
|
176
176
|
arg[:is_utf8] = true
|
177
177
|
parse!(spx, arg)
|
178
178
|
end
|
data/lib/icu_tournament/util.rb
CHANGED
@@ -1,166 +1,167 @@
|
|
1
1
|
module ICU
|
2
2
|
module Util
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
3
|
+
module Date
|
4
|
+
# Parse dates into yyyy-mm-dd format, preferring European over US convention. Returns nil on error.
|
5
|
+
#
|
6
|
+
# Date.parse('1955-11-09') # => '1955-11-09'
|
7
|
+
# Date.parse('02/03/2009') # => '2009-03-02'
|
8
|
+
# Date.parse('02/23/2009') # => '2009-02-23'
|
9
|
+
# Date.parse('16th June 1986') # => '1986-06-16'
|
10
|
+
#
|
11
|
+
# Note that the parse method of the Date class behaves differently in Ruby 1.8 and 1.9.
|
12
|
+
# In 1.8 it assumes American dates and will raise ArgumentError on "30/03/2003".
|
13
|
+
# In 1.9 it assumes European dates and will raise ArgumentError on "03/30/2003".
|
14
|
+
def self.parse(date)
|
15
|
+
date = date.to_s.strip
|
16
|
+
return nil unless date.match(/[1-9]/)
|
17
|
+
date = [$3].concat($2.to_i > 12 ? [$1, $2] : [$2, $1]).join('-') if date.match(/^(\d{1,2}).(\d{1,2}).(\d{4})$/)
|
18
|
+
begin
|
19
|
+
::Date.parse(date, true).to_s
|
20
|
+
rescue
|
21
|
+
nil
|
22
|
+
end
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
module File
|
27
|
+
# Read UTF data from a file.
|
28
|
+
def self.read_utf8(name)
|
29
|
+
::File.open(name, "r:ASCII-8BIT") do |f|
|
30
|
+
data = f.read
|
31
|
+
bom = "\xEF\xBB\xBF".force_encoding("ASCII-8BIT")
|
32
|
+
data.sub!(/^#{bom}/, "") # get rid of a UTF-8 BOM
|
33
|
+
ICU::Util::String.to_utf8(data) # defined in icu_name
|
34
|
+
end
|
32
35
|
end
|
33
|
-
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
37
|
+
# Load an INI file and convert to a hash.
|
38
|
+
def self.load_ini(name)
|
39
|
+
text = self.read_utf8(name)
|
40
|
+
data = Hash.new
|
41
|
+
header = nil
|
42
|
+
text.split(/\n/).each do |line|
|
43
|
+
if line.match(/^\s*\[([^\]]+)\]\s*$/)
|
44
|
+
header = $1.strip
|
45
|
+
header = nil if header == ""
|
46
|
+
elsif header && line.match(/^([^=]+)=(.*)$/)
|
47
|
+
key = $1.strip
|
48
|
+
val = $2.strip
|
49
|
+
unless key == ""
|
50
|
+
data[header] ||= Hash.new
|
51
|
+
data[header][key] = val
|
52
|
+
end
|
50
53
|
end
|
51
54
|
end
|
55
|
+
data
|
52
56
|
end
|
53
|
-
data
|
54
57
|
end
|
55
|
-
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
instance_variable_set("@#{name}", val)
|
59
|
+
# Miscellaneous accessor helpers.
|
60
|
+
module Accessor
|
61
|
+
def attr_accessor(name, &block)
|
62
|
+
attr_reader name
|
63
|
+
if block
|
64
|
+
define_method("#{name}=") do |val|
|
65
|
+
val = block.call(val)
|
66
|
+
instance_variable_set("@#{name}", val)
|
67
|
+
end
|
67
68
|
end
|
68
69
|
end
|
69
|
-
end
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
71
|
+
def attr_integer(*names)
|
72
|
+
names.each do |name|
|
73
|
+
attr_accessor(name) do |val|
|
74
|
+
tmp = val.to_i
|
75
|
+
raise "invalid integer (#{val}) for #{name}" unless val.is_a?(Fixnum) || (val.is_a?(::String) && val.include?(tmp.to_s))
|
76
|
+
tmp
|
77
|
+
end
|
77
78
|
end
|
78
79
|
end
|
79
|
-
end
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
81
|
+
def attr_integer_or_nil(*names)
|
82
|
+
names.each do |name|
|
83
|
+
attr_accessor(name) do |val|
|
84
|
+
tmp = case val
|
85
|
+
when nil then nil
|
86
|
+
when Fixnum then val
|
87
|
+
when /^\s*$/ then nil
|
88
|
+
else val.to_i
|
89
|
+
end
|
90
|
+
raise "invalid integer (#{val}) for #{name}" if tmp == 0 && val.is_a?(::String) && !val.include?('0')
|
91
|
+
tmp
|
89
92
|
end
|
90
|
-
raise "invalid integer (#{val}) for #{name}" if tmp == 0 && val.is_a?(String) && !val.include?('0')
|
91
|
-
tmp
|
92
93
|
end
|
93
94
|
end
|
94
|
-
end
|
95
95
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
96
|
+
def attr_positive(*names)
|
97
|
+
names.each do |name|
|
98
|
+
attr_accessor(name) do |val|
|
99
|
+
tmp = val.to_i
|
100
|
+
raise "invalid positive integer (#{val}) for #{name}" unless tmp > 0
|
101
|
+
tmp
|
102
|
+
end
|
102
103
|
end
|
103
104
|
end
|
104
|
-
end
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
106
|
+
def attr_positive_or_nil(*names)
|
107
|
+
names.each do |name|
|
108
|
+
attr_accessor(name) do |val|
|
109
|
+
tmp = case val
|
110
|
+
when nil then nil
|
111
|
+
when Fixnum then val
|
112
|
+
when /^\s*$/ then nil
|
113
|
+
else val.to_i
|
114
|
+
end
|
115
|
+
raise "invalid positive integer or nil (#{val}) for #{name}" unless tmp.nil? || tmp > 0
|
116
|
+
tmp
|
114
117
|
end
|
115
|
-
raise "invalid positive integer or nil (#{val}) for #{name}" unless tmp.nil? || tmp > 0
|
116
|
-
tmp
|
117
118
|
end
|
118
119
|
end
|
119
|
-
end
|
120
120
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
121
|
+
def attr_date(*names)
|
122
|
+
names.each do |name|
|
123
|
+
attr_accessor(name) do |val|
|
124
|
+
tmp = val.to_s.strip
|
125
|
+
tmp = ICU::Util::Date::parse(tmp)
|
126
|
+
raise "invalid date (#{val}) for #{name}" unless tmp
|
127
|
+
tmp
|
128
|
+
end
|
128
129
|
end
|
129
130
|
end
|
130
|
-
end
|
131
131
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
132
|
+
def attr_date_or_nil(*names)
|
133
|
+
names.each do |name|
|
134
|
+
attr_accessor(name) do |val|
|
135
|
+
tmp = val.to_s.strip
|
136
|
+
if tmp == ''
|
137
|
+
tmp = nil
|
138
|
+
else
|
139
|
+
tmp = ICU::Util::Date::parse(tmp)
|
140
|
+
raise "invalid date or nil (#{val}) for #{name}" unless tmp
|
141
|
+
end
|
142
|
+
tmp
|
141
143
|
end
|
142
|
-
tmp
|
143
144
|
end
|
144
145
|
end
|
145
|
-
end
|
146
146
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
147
|
+
def attr_string(regex, *names)
|
148
|
+
names.each do |name|
|
149
|
+
attr_accessor(name) do |val|
|
150
|
+
tmp = val.to_s.strip
|
151
|
+
raise "invalid #{name} (#{val})" unless tmp.match(regex)
|
152
|
+
tmp
|
153
|
+
end
|
153
154
|
end
|
154
155
|
end
|
155
|
-
end
|
156
156
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
157
|
+
def attr_string_or_nil(regex, *names)
|
158
|
+
names.each do |name|
|
159
|
+
attr_accessor(name) do |val|
|
160
|
+
tmp = val.to_s.strip
|
161
|
+
tmp = nil if tmp == ''
|
162
|
+
raise "invalid #{name} (#{val})" unless tmp.nil? || tmp.match(regex)
|
163
|
+
tmp
|
164
|
+
end
|
164
165
|
end
|
165
166
|
end
|
166
167
|
end
|
data/spec/util_spec.rb
CHANGED
@@ -2,430 +2,434 @@
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
3
|
|
4
4
|
module ICU
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
5
|
+
module Util
|
6
|
+
describe Date do
|
7
|
+
context "#parse" do
|
8
|
+
it "should parse standard dates" do
|
9
|
+
Date.parse('2001-01-01').should == '2001-01-01'
|
10
|
+
Date.parse('1955-11-09').should == '1955-11-09'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should handle US format" do
|
14
|
+
Date.parse('03/30/2009').should == '2009-03-30'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should handle European format" do
|
18
|
+
Date.parse('30/03/2009').should == '2009-03-30'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should prefer European format" do
|
22
|
+
Date.parse('02/03/2009').should == '2009-03-02'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should handle US style when there's no alternative" do
|
26
|
+
Date.parse('02/23/2009').should == '2009-02-23'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should handle single digits" do
|
30
|
+
Date.parse('9/8/2006').should == '2006-08-09'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should handle names of monthsx" do
|
34
|
+
Date.parse('9th Nov 1955').should == '1955-11-09'
|
35
|
+
Date.parse('16th June 1986').should == '1986-06-16'
|
36
|
+
end
|
35
37
|
end
|
36
38
|
end
|
39
|
+
|
40
|
+
describe File do
|
41
|
+
context "#read_utf8" do
|
42
|
+
before(:all) do
|
43
|
+
@s = ::File.dirname(__FILE__) + '/samples/file'
|
44
|
+
end
|
37
45
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should read ASCII" do
|
44
|
-
Util.read_utf8("#{@s}/ascii.txt").should == "Resume\nResume\n"
|
45
|
-
end
|
46
|
+
it "should read ASCII" do
|
47
|
+
File.read_utf8("#{@s}/ascii.txt").should == "Resume\nResume\n"
|
48
|
+
end
|
46
49
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
+
it "should read Latin-1" do
|
51
|
+
File.read_utf8("#{@s}/latin1.txt").should == "Résumé\nRésumé\n"
|
52
|
+
end
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
it "should read Windows CP1252" do
|
55
|
+
File.read_utf8("#{@s}/cp1252.txt").should == "€3\n£7\n¥1\n"
|
56
|
+
end
|
54
57
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
+
it "should read UTF-8" do
|
59
|
+
File.read_utf8("#{@s}/utf8.txt").should == "ヒラガナ\nヒラガナ\n"
|
60
|
+
end
|
58
61
|
|
59
|
-
|
60
|
-
|
62
|
+
it "should thow an exception for a non-existant file" do
|
63
|
+
lambda { File.read_utf8("#{@s}/no_such_file.txt") }.should raise_error
|
64
|
+
end
|
61
65
|
end
|
62
|
-
end
|
63
66
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
67
|
+
context "#load_ini" do
|
68
|
+
before(:all) do
|
69
|
+
@s = ::File.dirname(__FILE__) + '/samples/ini'
|
70
|
+
end
|
68
71
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
it "should read ASCII" do
|
73
|
+
data = File.load_ini("#{@s}/ascii.ini")
|
74
|
+
data.should be_an_instance_of(Hash)
|
75
|
+
data["Pairing"]["UseRating"].should == "0"
|
76
|
+
data["NoKeys"] == nil
|
77
|
+
data["Tournament Info"]["Arbiter"].should == "Herbert Scarry"
|
78
|
+
data["Tournament Info"]["DrawSymbol"].should == "D"
|
79
|
+
end
|
77
80
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
it "should read Latin1" do
|
82
|
+
data = File.load_ini("#{@s}/latin1.ini")
|
83
|
+
data.should be_an_instance_of(Hash)
|
84
|
+
data["Tournament Info"]["Arbiter"].should == "Gearóidín"
|
85
|
+
data["Tournament Info"]["DrawSymbol"].should == "½"
|
86
|
+
end
|
84
87
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
88
|
+
it "should read Windows-1252" do
|
89
|
+
data = File.load_ini("#{@s}/cp1252.ini")
|
90
|
+
data.should be_an_instance_of(Hash)
|
91
|
+
data["Tournament Info"]["Entry Fee"].should == "€50"
|
92
|
+
end
|
90
93
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
94
|
+
it "should read UTF8" do
|
95
|
+
data = File.load_ini("#{@s}/utf8.ini")
|
96
|
+
data.should be_an_instance_of(Hash)
|
97
|
+
data["Tournament Info"]["Entry Fee"].should == "€50"
|
98
|
+
data["Tournament Info"]["Arbiter"].should == "ヒラガナ"
|
99
|
+
data["Tournament Info"]["DrawSymbol"].should == "½"
|
100
|
+
end
|
98
101
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
102
|
+
it "should handle untidily formatted files" do
|
103
|
+
data = File.load_ini("#{@s}/untidy.ini")
|
104
|
+
data.should be_an_instance_of(Hash)
|
105
|
+
data["Tournament Info"]["Entry Fee"].should == "€50"
|
106
|
+
data["Tournament Info"]["DrawSymbol"].should == "½"
|
107
|
+
data["Pairing"]["Use Rating"].should == "0"
|
108
|
+
end
|
106
109
|
|
107
|
-
|
108
|
-
|
110
|
+
it "should thow an exception for a non-existant file" do
|
111
|
+
lambda { File.read_utf8("#{@s}/no_such_file.ini") }.should raise_error
|
112
|
+
end
|
109
113
|
end
|
110
114
|
end
|
111
|
-
end
|
112
115
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
116
|
+
describe Accessor do
|
117
|
+
context "#attr_accessor" do
|
118
|
+
before(:each) do
|
119
|
+
@class = Class.new
|
120
|
+
@class.extend ICU::Util::Accessor
|
121
|
+
@obj = @class.new
|
122
|
+
end
|
120
123
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
124
|
+
it "should not have an accessor unless declared" do
|
125
|
+
@obj.respond_to?(:myatr).should be_false
|
126
|
+
@obj.respond_to?(:myatr=).should be_false
|
127
|
+
end
|
125
128
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
it "should have a getter but no setter with the default declaration" do
|
130
|
+
@class.attr_accessor('myatr')
|
131
|
+
@obj.respond_to?(:myatr).should be_true
|
132
|
+
@obj.respond_to?(:myatr=).should be_false
|
133
|
+
@obj.instance_eval { @myatr = 42 }
|
134
|
+
@obj.myatr.should == 42
|
135
|
+
end
|
133
136
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
137
|
+
it "should be able to create do-it-yourself setters such as for a positive integer" do
|
138
|
+
@class.attr_accessor('myatr') do |val|
|
139
|
+
tmp = val.to_i
|
140
|
+
raise "invalid positive integer (#{val})" unless tmp > 0
|
141
|
+
tmp
|
142
|
+
end
|
143
|
+
@obj.respond_to?(:myatr).should be_true
|
144
|
+
@obj.respond_to?(:myatr=).should be_true
|
145
|
+
lambda { @obj.myatr = "no number here" }.should raise_error(/invalid positive integer \(no number here\)/)
|
146
|
+
lambda { @obj.myatr = -1 }.should raise_error
|
147
|
+
lambda { @obj.myatr = 0 }.should raise_error
|
148
|
+
lambda { @obj.myatr = 1 }.should_not raise_error
|
149
|
+
@obj.myatr.should == 1
|
150
|
+
lambda { @obj.myatr = '42' }.should_not raise_error
|
151
|
+
@obj.myatr.should == 42
|
152
|
+
lambda { @obj.myatr = ' 0371 ' }.should_not raise_error
|
153
|
+
@obj.myatr.should == 371
|
154
|
+
end
|
151
155
|
end
|
152
|
-
end
|
153
156
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
157
|
+
context "#attr_integer" do
|
158
|
+
before(:each) do
|
159
|
+
@class = Class.new
|
160
|
+
@class.extend ICU::Util::Accessor
|
161
|
+
@class.attr_integer :myint
|
162
|
+
@obj = @class.new
|
163
|
+
end
|
161
164
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
165
|
+
it "should have a getter and setter" do
|
166
|
+
@obj.respond_to?(:myint).should be_true
|
167
|
+
@obj.respond_to?(:myint=).should be_true
|
168
|
+
end
|
166
169
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
170
|
+
it "should work with ints" do
|
171
|
+
@obj.myint = -43
|
172
|
+
@obj.myint.should == -43
|
173
|
+
end
|
171
174
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
175
|
+
it "should work with strings" do
|
176
|
+
@obj.myint = " -99 "
|
177
|
+
@obj.myint.should == -99
|
178
|
+
end
|
176
179
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
180
|
+
it "should handle zero" do
|
181
|
+
lambda { @obj.myint = 0 }.should_not raise_error
|
182
|
+
lambda { @obj.myint = '0' }.should_not raise_error
|
183
|
+
end
|
181
184
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
185
|
+
it "should reject nil and other non-numbers" do
|
186
|
+
lambda { @obj.myint = nil }.should raise_error(/invalid/)
|
187
|
+
lambda { @obj.myint = "N" }.should raise_error(/invalid/)
|
188
|
+
lambda { @obj.myint = " " }.should raise_error(/invalid/)
|
189
|
+
lambda { @obj.myint = '' }.should raise_error(/invalid/)
|
190
|
+
end
|
188
191
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
192
|
+
it "should handle multiple names" do
|
193
|
+
@class.attr_integer :yourint, :hisint
|
194
|
+
@obj.respond_to?(:yourint).should be_true
|
195
|
+
@obj.respond_to?(:hisint=).should be_true
|
196
|
+
end
|
193
197
|
end
|
194
|
-
end
|
195
198
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
199
|
+
context "#attr_integer_or_nil" do
|
200
|
+
before(:each) do
|
201
|
+
@class = Class.new
|
202
|
+
@class.extend ICU::Util::Accessor
|
203
|
+
@class.attr_integer_or_nil :myint
|
204
|
+
@obj = @class.new
|
205
|
+
end
|
203
206
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
207
|
+
it "should have a getter and setter" do
|
208
|
+
@obj.respond_to?(:myint).should be_true
|
209
|
+
@obj.respond_to?(:myint=).should be_true
|
210
|
+
end
|
208
211
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
212
|
+
it "should work with ints and nil and spaces" do
|
213
|
+
@obj.myint = 43
|
214
|
+
@obj.myint.should == 43
|
215
|
+
@obj.myint = nil
|
216
|
+
@obj.myint.should == nil
|
217
|
+
@obj.myint = ' '
|
218
|
+
@obj.myint.should == nil
|
219
|
+
end
|
217
220
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
+
it "should reject non-numbers" do
|
222
|
+
lambda { @obj.myint = "N" }.should raise_error(/invalid/)
|
223
|
+
end
|
221
224
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
225
|
+
it "should handle multiple names" do
|
226
|
+
@class.attr_integer :yourint, :hisint
|
227
|
+
@obj.respond_to?(:yourint).should be_true
|
228
|
+
@obj.respond_to?(:hisint=).should be_true
|
229
|
+
end
|
226
230
|
end
|
227
|
-
end
|
228
231
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
232
|
+
context "#attr_positive" do
|
233
|
+
before(:each) do
|
234
|
+
@class = Class.new
|
235
|
+
@class.extend ICU::Util::Accessor
|
236
|
+
@class.attr_positive :mypos
|
237
|
+
@obj = @class.new
|
238
|
+
end
|
236
239
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
240
|
+
it "should have a getter and setter" do
|
241
|
+
@obj.respond_to?(:mypos).should be_true
|
242
|
+
@obj.respond_to?(:mypos=).should be_true
|
243
|
+
end
|
241
244
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
245
|
+
it "should work as expected" do
|
246
|
+
@obj.mypos = "34"
|
247
|
+
@obj.mypos.should == 34
|
248
|
+
end
|
246
249
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
250
|
+
it "should reject nil and other non-positive integers" do
|
251
|
+
lambda { @obj.mypos = nil }.should raise_error(/invalid/)
|
252
|
+
lambda { @obj.mypos = 'X' }.should raise_error(/invalid/)
|
253
|
+
lambda { @obj.mypos = '0' }.should raise_error(/invalid/)
|
254
|
+
lambda { @obj.mypos = -13 }.should raise_error(/invalid/)
|
255
|
+
end
|
253
256
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
257
|
+
it "should handle multiple names" do
|
258
|
+
@class.attr_integer :ourpos, :theirpos
|
259
|
+
@obj.respond_to?(:ourpos).should be_true
|
260
|
+
@obj.respond_to?(:theirpos=).should be_true
|
261
|
+
end
|
258
262
|
end
|
259
|
-
end
|
260
263
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
264
|
+
context "#attr_positive_or_nil" do
|
265
|
+
before(:each) do
|
266
|
+
@class = Class.new
|
267
|
+
@class.extend ICU::Util::Accessor
|
268
|
+
@class.attr_positive_or_nil :mypon
|
269
|
+
@obj = @class.new
|
270
|
+
end
|
268
271
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
272
|
+
it "should have a getter and setter" do
|
273
|
+
@obj.respond_to?(:mypon).should be_true
|
274
|
+
@obj.respond_to?(:mypon=).should be_true
|
275
|
+
end
|
273
276
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
277
|
+
it "should work with numbers, nil, empty strings and spaces" do
|
278
|
+
@obj.mypon = " 54 "
|
279
|
+
@obj.mypon.should == 54
|
280
|
+
@obj.mypon = nil
|
281
|
+
@obj.mypon.should be_nil
|
282
|
+
@obj.mypon = ''
|
283
|
+
@obj.mypon.should be_nil
|
284
|
+
@obj.mypon = ' '
|
285
|
+
@obj.mypon.should be_nil
|
286
|
+
end
|
284
287
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
288
|
+
it "should reject non-integers and non-positive integers" do
|
289
|
+
lambda { @obj.mypon = 'X' }.should raise_error(/invalid/)
|
290
|
+
lambda { @obj.mypon = '0' }.should raise_error(/invalid/)
|
291
|
+
lambda { @obj.mypon = -13 }.should raise_error(/invalid/)
|
292
|
+
end
|
290
293
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
294
|
+
it "should handle multiple names" do
|
295
|
+
@class.attr_integer :ourpon, :theirpon
|
296
|
+
@obj.respond_to?(:ourpon).should be_true
|
297
|
+
@obj.respond_to?(:theirpon=).should be_true
|
298
|
+
end
|
295
299
|
end
|
296
|
-
end
|
297
300
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
301
|
+
context "#attr_date" do
|
302
|
+
before(:each) do
|
303
|
+
@class = Class.new
|
304
|
+
@class.extend ICU::Util::Accessor
|
305
|
+
@class.attr_date :mydate
|
306
|
+
@obj = @class.new
|
307
|
+
end
|
305
308
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
309
|
+
it "should have a getter and setter" do
|
310
|
+
@obj.respond_to?(:mydate).should be_true
|
311
|
+
@obj.respond_to?(:mydate=).should be_true
|
312
|
+
end
|
310
313
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
314
|
+
it "should work as expected" do
|
315
|
+
@obj.mydate = "2009/11/09"
|
316
|
+
@obj.mydate.should == '2009-11-09'
|
317
|
+
end
|
315
318
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
319
|
+
it "should reject nil and other non-dates" do
|
320
|
+
lambda { @obj.mydate = nil }.should raise_error(/invalid/)
|
321
|
+
lambda { @obj.mydate = 'blah de blah' }.should raise_error(/invalid/)
|
322
|
+
lambda { @obj.mydate = ' ' }.should raise_error(/invalid/)
|
323
|
+
lambda { @obj.mydate = 0 }.should raise_error(/invalid/)
|
324
|
+
end
|
322
325
|
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
326
|
+
it "should handle multiple names" do
|
327
|
+
@class.attr_date :ourdate, :theirdate
|
328
|
+
@obj.respond_to?(:ourdate).should be_true
|
329
|
+
@obj.respond_to?(:theirdate=).should be_true
|
330
|
+
end
|
327
331
|
end
|
328
|
-
end
|
329
332
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
333
|
+
context "#attr_date_or_nil" do
|
334
|
+
before(:each) do
|
335
|
+
@class = Class.new
|
336
|
+
@class.extend ICU::Util::Accessor
|
337
|
+
@class.attr_date_or_nil :mydate
|
338
|
+
@obj = @class.new
|
339
|
+
end
|
337
340
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
341
|
+
it "should have a getter and setter" do
|
342
|
+
@obj.respond_to?(:mydate).should be_true
|
343
|
+
@obj.respond_to?(:mydate=).should be_true
|
344
|
+
end
|
342
345
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
346
|
+
it "should work as expected, including with nil" do
|
347
|
+
@obj.mydate = "2009/11/09"
|
348
|
+
@obj.mydate.should == '2009-11-09'
|
349
|
+
@obj.mydate = nil
|
350
|
+
@obj.mydate.should be_nil
|
351
|
+
end
|
349
352
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
353
|
+
it "should reject non-dates" do
|
354
|
+
lambda { @obj.mydate = 'blah de blah' }.should raise_error(/invalid/)
|
355
|
+
lambda { @obj.mydate = 0 }.should raise_error(/invalid/)
|
356
|
+
end
|
354
357
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
358
|
+
it "should handle multiple names" do
|
359
|
+
@class.attr_date :ourdate, :theirdate
|
360
|
+
@obj.respond_to?(:ourdate).should be_true
|
361
|
+
@obj.respond_to?(:theirdate=).should be_true
|
362
|
+
end
|
359
363
|
end
|
360
|
-
end
|
361
364
|
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
365
|
+
context "#attr_string" do
|
366
|
+
before(:each) do
|
367
|
+
@class = Class.new
|
368
|
+
@class.extend ICU::Util::Accessor
|
369
|
+
@class.attr_string %r%[a-z]+%i, :mystring
|
370
|
+
@obj = @class.new
|
371
|
+
end
|
369
372
|
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
373
|
+
it "should have a getter and setter" do
|
374
|
+
@obj.respond_to?(:mystring).should be_true
|
375
|
+
@obj.respond_to?(:mystring=).should be_true
|
376
|
+
end
|
374
377
|
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
378
|
+
it "should work as expected" do
|
379
|
+
@obj.mystring = " mark "
|
380
|
+
@obj.mystring.should == 'mark'
|
381
|
+
end
|
379
382
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
383
|
+
it "should reject values that don't match" do
|
384
|
+
lambda { @obj.mystring = nil }.should raise_error(/invalid/)
|
385
|
+
lambda { @obj.mystring = ' 123 ' }.should raise_error(/invalid/)
|
386
|
+
lambda { @obj.mystring = ' ' }.should raise_error(/invalid/)
|
387
|
+
lambda { @obj.mystring = 0 }.should raise_error(/invalid/)
|
388
|
+
lambda { @obj.mystring = ' a ' }.should_not raise_error
|
389
|
+
lambda { @obj.mystring = 'ZYX' }.should_not raise_error
|
390
|
+
end
|
388
391
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
392
|
+
it "should handle multiple names" do
|
393
|
+
@class.attr_string %r%^[A-Z]{3}$%, :ourstring, :theirstring
|
394
|
+
@obj.respond_to?(:ourstring=).should be_true
|
395
|
+
@obj.respond_to?(:theirstring).should be_true
|
396
|
+
end
|
393
397
|
end
|
394
|
-
end
|
395
398
|
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
399
|
+
context "#attr_string_or_nil" do
|
400
|
+
before(:each) do
|
401
|
+
@class = Class.new
|
402
|
+
@class.extend ICU::Util::Accessor
|
403
|
+
@class.attr_string_or_nil %r%^[1-9]\d*$%i, :mystring
|
404
|
+
@obj = @class.new
|
405
|
+
end
|
403
406
|
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
407
|
+
it "should have a getter and setter" do
|
408
|
+
@obj.respond_to?(:mystring).should be_true
|
409
|
+
@obj.respond_to?(:mystring=).should be_true
|
410
|
+
end
|
408
411
|
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
412
|
+
it "should work as expected" do
|
413
|
+
@obj.mystring = " 12345 "
|
414
|
+
@obj.mystring.should == '12345'
|
415
|
+
@obj.mystring = nil
|
416
|
+
@obj.mystring.should be_nil
|
417
|
+
@obj.mystring = ' '
|
418
|
+
@obj.mystring.should be_nil
|
419
|
+
end
|
417
420
|
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
421
|
+
it "should reject values that don't match" do
|
422
|
+
lambda { @obj.mystring = ' 0 ' }.should raise_error(/invalid/)
|
423
|
+
lambda { @obj.mystring = 0 }.should raise_error(/invalid/)
|
424
|
+
lambda { @obj.mystring = -1 }.should raise_error(/invalid/)
|
425
|
+
lambda { @obj.mystring = 98 }.should_not raise_error
|
426
|
+
end
|
424
427
|
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
428
|
+
it "should handle multiple names" do
|
429
|
+
@class.attr_string %r%^[A-Z][a-z]+%, :ourstring, :theirstring
|
430
|
+
@obj.respond_to?(:ourstring=).should be_true
|
431
|
+
@obj.respond_to?(:theirstring).should be_true
|
432
|
+
end
|
429
433
|
end
|
430
434
|
end
|
431
435
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icu_tournament
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dbf
|
@@ -174,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
174
|
version: '0'
|
175
175
|
segments:
|
176
176
|
- 0
|
177
|
-
hash:
|
177
|
+
hash: 906985998380119772
|
178
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
179
|
none: false
|
180
180
|
requirements:
|
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
183
|
version: '0'
|
184
184
|
segments:
|
185
185
|
- 0
|
186
|
-
hash:
|
186
|
+
hash: 906985998380119772
|
187
187
|
requirements: []
|
188
188
|
rubyforge_project: icu_tournament
|
189
189
|
rubygems_version: 1.8.23
|