icu_tournament 1.8.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/icu_tournament/player.rb +1 -1
- data/lib/icu_tournament/tournament.rb +1 -1
- data/lib/icu_tournament/version.rb +1 -1
- data/lib/icu_tournament.rb +2 -1
- metadata +20 -7
- data/lib/icu_tournament/federation.rb +0 -309
- data/spec/federation_spec.rb +0 -190
|
@@ -142,7 +142,7 @@ module ICU
|
|
|
142
142
|
|
|
143
143
|
# Federation. Is either unknown (nil) or a string containing at least three letters.
|
|
144
144
|
def fed=(fed)
|
|
145
|
-
obj = Federation.find(fed)
|
|
145
|
+
obj = ICU::Federation.find(fed)
|
|
146
146
|
@fed = obj ? obj.code : nil
|
|
147
147
|
raise "invalid federation (#{fed})" if @fed.nil? && fed.to_s.strip.length > 0
|
|
148
148
|
end
|
|
@@ -216,7 +216,7 @@ module ICU
|
|
|
216
216
|
|
|
217
217
|
# Set the tournament federation. Can be _nil_.
|
|
218
218
|
def fed=(fed)
|
|
219
|
-
obj = Federation.find(fed)
|
|
219
|
+
obj = ICU::Federation.find(fed)
|
|
220
220
|
@fed = obj ? obj.code : nil
|
|
221
221
|
raise "invalid tournament federation (#{fed})" if @fed.nil? && fed.to_s.strip.length > 0
|
|
222
222
|
end
|
data/lib/icu_tournament.rb
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# :enddoc:
|
|
2
2
|
|
|
3
3
|
require 'icu_name'
|
|
4
|
+
require 'icu_utils'
|
|
4
5
|
|
|
5
6
|
icu_tournament_files = Array.new
|
|
6
|
-
icu_tournament_files.concat %w{util
|
|
7
|
+
icu_tournament_files.concat %w{util tie_break}
|
|
7
8
|
icu_tournament_files.concat %w{player result team tournament}
|
|
8
9
|
icu_tournament_files.concat %w{fcsv krause sp spx}.map{ |f| "tournament_#{f}"}
|
|
9
10
|
|
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.9.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-11-02 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: dbf
|
|
@@ -59,6 +59,22 @@ dependencies:
|
|
|
59
59
|
- - ! '>='
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
61
|
version: '0'
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: icu_utils
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
type: :runtime
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
62
78
|
- !ruby/object:Gem::Dependency
|
|
63
79
|
name: bundler
|
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -132,7 +148,6 @@ extra_rdoc_files:
|
|
|
132
148
|
- LICENCE
|
|
133
149
|
- README.rdoc
|
|
134
150
|
files:
|
|
135
|
-
- lib/icu_tournament/federation.rb
|
|
136
151
|
- lib/icu_tournament/player.rb
|
|
137
152
|
- lib/icu_tournament/result.rb
|
|
138
153
|
- lib/icu_tournament/team.rb
|
|
@@ -145,7 +160,6 @@ files:
|
|
|
145
160
|
- lib/icu_tournament/util.rb
|
|
146
161
|
- lib/icu_tournament/version.rb
|
|
147
162
|
- lib/icu_tournament.rb
|
|
148
|
-
- spec/federation_spec.rb
|
|
149
163
|
- spec/player_spec.rb
|
|
150
164
|
- spec/result_spec.rb
|
|
151
165
|
- spec/spec_helper.rb
|
|
@@ -174,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
174
188
|
version: '0'
|
|
175
189
|
segments:
|
|
176
190
|
- 0
|
|
177
|
-
hash:
|
|
191
|
+
hash: 3282717942212095260
|
|
178
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
193
|
none: false
|
|
180
194
|
requirements:
|
|
@@ -183,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
183
197
|
version: '0'
|
|
184
198
|
segments:
|
|
185
199
|
- 0
|
|
186
|
-
hash:
|
|
200
|
+
hash: 3282717942212095260
|
|
187
201
|
requirements: []
|
|
188
202
|
rubyforge_project: icu_tournament
|
|
189
203
|
rubygems_version: 1.8.23
|
|
@@ -191,7 +205,6 @@ signing_key:
|
|
|
191
205
|
specification_version: 3
|
|
192
206
|
summary: For reading and writing files of chess tournament data.
|
|
193
207
|
test_files:
|
|
194
|
-
- spec/federation_spec.rb
|
|
195
208
|
- spec/player_spec.rb
|
|
196
209
|
- spec/result_spec.rb
|
|
197
210
|
- spec/spec_helper.rb
|
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
module ICU
|
|
2
|
-
#
|
|
3
|
-
# This class can be used to map a string into an object representing a chess federation.
|
|
4
|
-
# In FIDE, chess federations are generally either referred to by their full names such as
|
|
5
|
-
# _Ireland_ or _Russia_ or by three letter codes such as _IRL_ or _RUS_. The three letter
|
|
6
|
-
# codes are mostly the same as those found in the international standard known as
|
|
7
|
-
# {ISO 3166-1 alpha-3}[http://en.wikipedia.org/wiki/ISO_3166-1_alpha-3], but with
|
|
8
|
-
# some differences (e.g. for England, Scotland and Wales).
|
|
9
|
-
#
|
|
10
|
-
# You cannot directly create instances of this class using _new_. Instead, you supply
|
|
11
|
-
# a string to the class method _find_ and, if the string supplied uniguely identifies a
|
|
12
|
-
# federation, an instance is returned which responds to _name_ and _code_.
|
|
13
|
-
#
|
|
14
|
-
# fed = ICU::Federation.find('IRL')
|
|
15
|
-
# fed.name # => "Ireland"
|
|
16
|
-
# fed.code # => "IRL"
|
|
17
|
-
#
|
|
18
|
-
# If the string is not sufficient to identify a federation, the _find_ method returns _nil_.
|
|
19
|
-
#
|
|
20
|
-
# fed = ICU::Federation.find('ZYX') # => nil
|
|
21
|
-
#
|
|
22
|
-
# If the string is three letters long and matches (case insenstively) one of the unique
|
|
23
|
-
# federation codes, then the instance corresponding to that federation is returned.
|
|
24
|
-
#
|
|
25
|
-
# ICU::Federation.find('rUs').code # => "RUS"
|
|
26
|
-
#
|
|
27
|
-
# If the string is more than three letters long and if it is a substring (case insensitive)
|
|
28
|
-
# of exactly one federation name, then that federation is returned.
|
|
29
|
-
#
|
|
30
|
-
# ICU::Federation.find('ongoli').name # => "Mongolia"
|
|
31
|
-
#
|
|
32
|
-
# In all other cases, nil is returned. In the following example, the string matches more than one federation.
|
|
33
|
-
#
|
|
34
|
-
# ICU::Federation.find('land') # => nil
|
|
35
|
-
#
|
|
36
|
-
# The method is not fooled by irrelevant white space.
|
|
37
|
-
#
|
|
38
|
-
# ICU::Federation.find(' united states ').code # => 'USA'
|
|
39
|
-
#
|
|
40
|
-
# The class method _menu_ will return an array of two-element arrays each of which contain a name
|
|
41
|
-
# and a code.
|
|
42
|
-
#
|
|
43
|
-
# ICU::Federation.menu # => [['Afghanistan', 'AFG'], ['Albania', 'ALB], ...]
|
|
44
|
-
#
|
|
45
|
-
# Such an array could be used, for example, as the basis of a selection menu in a web application.
|
|
46
|
-
# Various options are available to alter the array returned. Use the _:order_ option to order by code
|
|
47
|
-
# instead of the default (by country name).
|
|
48
|
-
#
|
|
49
|
-
# ICU::Federation.menu(:order => 'code') # => [..., ['Ireland', 'IRL'], ['Iraq', 'IRQ], ...]
|
|
50
|
-
#
|
|
51
|
-
# To put one country at the top (followed by the rest, in order) supply the country's code with the _:top_ option:
|
|
52
|
-
#
|
|
53
|
-
# ICU::Federation.menu(:top => 'IRL') # => [['Ireland', 'IRL'], ['Afghanistan', 'AFG], ...]
|
|
54
|
-
#
|
|
55
|
-
# To supply an extra "None" item at the top, specify its label with the _:none_ option:
|
|
56
|
-
#
|
|
57
|
-
# ICU::Federation.menu(:none => 'None') # => [['None', ''], ['Afghanistan', 'AFG], ...]
|
|
58
|
-
#
|
|
59
|
-
# The "None" option's code is the empty string and it comes above the "top" option if both are specified.
|
|
60
|
-
#
|
|
61
|
-
class Federation
|
|
62
|
-
attr_reader :code, :name
|
|
63
|
-
private_class_method :new
|
|
64
|
-
|
|
65
|
-
# Given a code, name or part of a name, return the corresponding federation instance.
|
|
66
|
-
# If there is no match or more than one match, _nil_ is returned.
|
|
67
|
-
def self.find(str=nil)
|
|
68
|
-
return nil unless str
|
|
69
|
-
str = str.to_s
|
|
70
|
-
return nil if str.length < 3
|
|
71
|
-
compile
|
|
72
|
-
str = str.strip.squeeze(' ').downcase
|
|
73
|
-
return @@codes[str] if str.length == 3
|
|
74
|
-
return @@names[str] if @@names[str]
|
|
75
|
-
matches = Array.new
|
|
76
|
-
@@names.each_key do |name|
|
|
77
|
-
matches << @@names[name] if name.index(str)
|
|
78
|
-
end
|
|
79
|
-
matches.uniq!
|
|
80
|
-
return nil unless matches.length == 1
|
|
81
|
-
matches[0]
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
# Return an array of codes and names suitable for creating a federation menu in Rails.
|
|
85
|
-
# ICU::Federation.menu(:order => 'code') # order federations by code (instead of by name)
|
|
86
|
-
# ICU::Federation.menu(:top => 'IRL') # make this federation come first
|
|
87
|
-
# ICU::Federation.menu(:none => 'None') # add a dummy top entry with name "None" and blank code
|
|
88
|
-
def self.menu(opts = {})
|
|
89
|
-
compile
|
|
90
|
-
top, menu = nil, []
|
|
91
|
-
@@objects.each {|o| opts[:top] == o.code ? top = [o.name, o.code] : menu.push([o.name, o.code]) }
|
|
92
|
-
opts[:order] == 'code' ? menu.sort!{|a,b| a.last <=> b.last} : menu.sort!{|a,b| a.first <=> b.first}
|
|
93
|
-
menu.unshift(top) if top
|
|
94
|
-
menu.unshift([opts[:none], '']) if opts[:none]
|
|
95
|
-
menu
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
# Return an array of sorted federation codes.
|
|
99
|
-
def self.codes
|
|
100
|
-
compile
|
|
101
|
-
@@objects.map(&:code).sort
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def initialize(code, name) # :nodoc: because new is private
|
|
105
|
-
@code = code
|
|
106
|
-
@name = name
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
# :enddoc:
|
|
110
|
-
private
|
|
111
|
-
|
|
112
|
-
def self.compile
|
|
113
|
-
return if @@objects
|
|
114
|
-
@@names = Hash.new
|
|
115
|
-
@@codes = Hash.new
|
|
116
|
-
@@objects = Array.new
|
|
117
|
-
@@data.each do |d|
|
|
118
|
-
object = new(d[0], d[1])
|
|
119
|
-
@@objects << object
|
|
120
|
-
@@codes[d[0].downcase] = object
|
|
121
|
-
(1..d.length-1).each do |i|
|
|
122
|
-
@@names[d[i].downcase] = object
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
# The data structures compiled.
|
|
128
|
-
@@objects, @@codes, @@names = nil, nil, nil
|
|
129
|
-
|
|
130
|
-
# An array of data that gets compiled into other data structures.
|
|
131
|
-
@@data =
|
|
132
|
-
[
|
|
133
|
-
['AFG', 'Afghanistan'],
|
|
134
|
-
['ALB', 'Albania'],
|
|
135
|
-
['ALG', 'Algeria'],
|
|
136
|
-
['AND', 'Andorra'],
|
|
137
|
-
['ANG', 'Angola'],
|
|
138
|
-
['ANT', 'Antigua'],
|
|
139
|
-
['ARG', 'Argentina'],
|
|
140
|
-
['ARM', 'Armenia'],
|
|
141
|
-
['ARU', 'Aruba'],
|
|
142
|
-
['AUS', 'Australia'],
|
|
143
|
-
['AUT', 'Austria'],
|
|
144
|
-
['AZE', 'Azerbaijan'],
|
|
145
|
-
['BAH', 'Bahamas'],
|
|
146
|
-
['BRN', 'Bahrain'],
|
|
147
|
-
['BAN', 'Bangladesh'],
|
|
148
|
-
['BAR', 'Barbados'],
|
|
149
|
-
['BLR', 'Belarus'],
|
|
150
|
-
['BEL', 'Belgium'],
|
|
151
|
-
['BIZ', 'Belize'],
|
|
152
|
-
['BEN', 'Benin Republic'],
|
|
153
|
-
['BER', 'Bermuda'],
|
|
154
|
-
['BHU', 'Bhutan'],
|
|
155
|
-
['BOL', 'Bolivia'],
|
|
156
|
-
['BIH', 'Bosnia and Herzegovina'],
|
|
157
|
-
['BOT', 'Botswana'],
|
|
158
|
-
['BRA', 'Brazil'],
|
|
159
|
-
['IVB', 'British Virgin Islands'],
|
|
160
|
-
['BRU', 'Brunei Darussalam'],
|
|
161
|
-
['BUL', 'Bulgaria'],
|
|
162
|
-
['BUR', 'Burkina Faso'],
|
|
163
|
-
['BDI', 'Burundi'],
|
|
164
|
-
['CAM', 'Cambodia'],
|
|
165
|
-
['CMR', 'Cameroon'],
|
|
166
|
-
['CAN', 'Canada'],
|
|
167
|
-
['CHA', 'Chad'],
|
|
168
|
-
['CHI', 'Chile'],
|
|
169
|
-
['CHN', 'China'],
|
|
170
|
-
['TPE', 'Chinese Taipei'],
|
|
171
|
-
['COL', 'Colombia'],
|
|
172
|
-
['CRC', 'Costa Rica'],
|
|
173
|
-
['CRO', 'Croatia'],
|
|
174
|
-
['CUB', 'Cuba'],
|
|
175
|
-
['CYP', 'Cyprus'],
|
|
176
|
-
['CZE', 'Czech Republic'],
|
|
177
|
-
['DEN', 'Denmark'],
|
|
178
|
-
['DJI', 'Djibouti'],
|
|
179
|
-
['DOM', 'Dominican Republic'],
|
|
180
|
-
['ECU', 'Ecuador'],
|
|
181
|
-
['EGY', 'Egypt'],
|
|
182
|
-
['ESA', 'El Salvador'],
|
|
183
|
-
['ENG', 'England'],
|
|
184
|
-
['EST', 'Estonia'],
|
|
185
|
-
['ETH', 'Ethiopia'],
|
|
186
|
-
['FAI', 'Faroe Islands'],
|
|
187
|
-
['FIJ', 'Fiji'],
|
|
188
|
-
['FIN', 'Finland'],
|
|
189
|
-
['FRA', 'France'],
|
|
190
|
-
['GAB', 'Gabon'],
|
|
191
|
-
['GAM', 'Gambia'],
|
|
192
|
-
['GEO', 'Georgia'],
|
|
193
|
-
['GER', 'Germany'],
|
|
194
|
-
['GHA', 'Ghana'],
|
|
195
|
-
['GRE', 'Greece'],
|
|
196
|
-
['GUA', 'Guatemala'],
|
|
197
|
-
['GCI', 'Guernsey'],
|
|
198
|
-
['GUY', 'Guyana'],
|
|
199
|
-
['HAI', 'Haiti'],
|
|
200
|
-
['HON', 'Honduras'],
|
|
201
|
-
['HKG', 'Hong Kong'],
|
|
202
|
-
['HUN', 'Hungary'],
|
|
203
|
-
['ISL', 'Iceland'],
|
|
204
|
-
['IND', 'India'],
|
|
205
|
-
['INA', 'Indonesia'],
|
|
206
|
-
['IRI', 'Iran'],
|
|
207
|
-
['IRQ', 'Iraq'],
|
|
208
|
-
['IRL', 'Ireland'],
|
|
209
|
-
['ISR', 'Israel'],
|
|
210
|
-
['ITA', 'Italy'],
|
|
211
|
-
['CIV', 'Ivory Coast'],
|
|
212
|
-
['JAM', 'Jamaica'],
|
|
213
|
-
['JPN', 'Japan'],
|
|
214
|
-
['JCI', 'Jersey'],
|
|
215
|
-
['JOR', 'Jordan'],
|
|
216
|
-
['KAZ', 'Kazakhstan'],
|
|
217
|
-
['KEN', 'Kenya'],
|
|
218
|
-
['KUW', 'Kuwait'],
|
|
219
|
-
['KGZ', 'Kyrgyzstan'],
|
|
220
|
-
['LAT', 'Latvia'],
|
|
221
|
-
['LIB', 'Lebanon'],
|
|
222
|
-
['LBA', 'Libya'],
|
|
223
|
-
['LIE', 'Liechtenstein'],
|
|
224
|
-
['LTU', 'Lithuania'],
|
|
225
|
-
['LUX', 'Luxembourg'],
|
|
226
|
-
['MAC', 'Macau'],
|
|
227
|
-
['MKD', 'Macedonia', 'Former YUG Rep of Macedonia', 'Former Yugoslav Republic of Macedonia', 'FYROM'],
|
|
228
|
-
['MAD', 'Madagascar'],
|
|
229
|
-
['MAW', 'Malawi'],
|
|
230
|
-
['MAS', 'Malaysia'],
|
|
231
|
-
['MDV', 'Maldives'],
|
|
232
|
-
['MLI', 'Mali'],
|
|
233
|
-
['MLT', 'Malta'],
|
|
234
|
-
['MAU', 'Mauritania'],
|
|
235
|
-
['MRI', 'Mauritius'],
|
|
236
|
-
['MEX', 'Mexico'],
|
|
237
|
-
['MDA', 'Moldova'],
|
|
238
|
-
['MNC', 'Monaco'],
|
|
239
|
-
['MGL', 'Mongolia'],
|
|
240
|
-
['MNE', 'Montenegro'],
|
|
241
|
-
['MAR', 'Morocco'],
|
|
242
|
-
['MOZ', 'Mozambique'],
|
|
243
|
-
['MYA', 'Myanmar'],
|
|
244
|
-
['NAM', 'Namibia'],
|
|
245
|
-
['NEP', 'Nepal'],
|
|
246
|
-
['NED', 'Netherlands'],
|
|
247
|
-
['AHO', 'Netherlands Antilles'],
|
|
248
|
-
['NZL', 'New Zealand'],
|
|
249
|
-
['NCA', 'Nicaragua'],
|
|
250
|
-
['NGR', 'Nigeria'],
|
|
251
|
-
['NOR', 'Norway'],
|
|
252
|
-
['PAK', 'Pakistan'],
|
|
253
|
-
['PLW', 'Palau'],
|
|
254
|
-
['PLE', 'Palestine'],
|
|
255
|
-
['PAN', 'Panama'],
|
|
256
|
-
['PNG', 'Papua New Guinea'],
|
|
257
|
-
['PAR', 'Paraguay'],
|
|
258
|
-
['PER', 'Peru'],
|
|
259
|
-
['PHI', 'Philippines'],
|
|
260
|
-
['POL', 'Poland'],
|
|
261
|
-
['POR', 'Portugal'],
|
|
262
|
-
['PUR', 'Puerto Rico'],
|
|
263
|
-
['QAT', 'Qatar'],
|
|
264
|
-
['ROU', 'Romania'],
|
|
265
|
-
['RUS', 'Russia'],
|
|
266
|
-
['RWA', 'Rwanda'],
|
|
267
|
-
['SMR', 'San Marino'],
|
|
268
|
-
['STP', 'Sao Tome and Principe'],
|
|
269
|
-
['SCO', 'Scotland'],
|
|
270
|
-
['SEN', 'Senegal'],
|
|
271
|
-
['SRB', 'Serbia'],
|
|
272
|
-
['SEY', 'Seychelles'],
|
|
273
|
-
['SLE', 'Siera Leone'],
|
|
274
|
-
['SIN', 'Singapore'],
|
|
275
|
-
['SVK', 'Slovakia'],
|
|
276
|
-
['SLO', 'Slovenia'],
|
|
277
|
-
['SOM', 'Somalia'],
|
|
278
|
-
['RSA', 'South Africa'],
|
|
279
|
-
['KOR', 'South Korea'],
|
|
280
|
-
['ESP', 'Spain'],
|
|
281
|
-
['SRI', 'Sri Lanka'],
|
|
282
|
-
['SUD', 'Sudan'],
|
|
283
|
-
['SUR', 'Surinam'],
|
|
284
|
-
['SWE', 'Sweden'],
|
|
285
|
-
['SUI', 'Switzerland'],
|
|
286
|
-
['SYR', 'Syria'],
|
|
287
|
-
['TJK', 'Tajikistan'],
|
|
288
|
-
['TAN', 'Tanzania'],
|
|
289
|
-
['THA', 'Thailand'],
|
|
290
|
-
['TRI', 'Trinidad and Tobago'],
|
|
291
|
-
['TUN', 'Tunisia'],
|
|
292
|
-
['TUR', 'Turkey'],
|
|
293
|
-
['TKM', 'Turkmenistan'],
|
|
294
|
-
['UGA', 'Uganda'],
|
|
295
|
-
['UKR', 'Ukraine'],
|
|
296
|
-
['UAE', 'United Arab Emirates'],
|
|
297
|
-
['USA', 'United States of America'],
|
|
298
|
-
['URU', 'Uruguay'],
|
|
299
|
-
['ISV', 'US Virgin Islands'],
|
|
300
|
-
['UZB', 'Uzbekistan'],
|
|
301
|
-
['VEN', 'Venezuela'],
|
|
302
|
-
['VIE', 'Vietnam'],
|
|
303
|
-
['WLS', 'Wales'],
|
|
304
|
-
['YEM', 'Yemen'],
|
|
305
|
-
['ZAM', 'Zambia'],
|
|
306
|
-
['ZIM', 'Zimbabwe'],
|
|
307
|
-
]
|
|
308
|
-
end
|
|
309
|
-
end
|
data/spec/federation_spec.rb
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
-
|
|
3
|
-
module ICU
|
|
4
|
-
describe Federation do
|
|
5
|
-
context "#find using codes" do
|
|
6
|
-
it "should find a federation given a valid code" do
|
|
7
|
-
fed = Federation.find('IRL')
|
|
8
|
-
fed.code.should == 'IRL'
|
|
9
|
-
fed.name.should == 'Ireland'
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "should find a federation from code case insensitively" do
|
|
13
|
-
fed = Federation.find('rUs')
|
|
14
|
-
fed.code.should == 'RUS'
|
|
15
|
-
fed.name.should == 'Russia'
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "should find a federation despite irrelevant whitespace" do
|
|
19
|
-
fed = Federation.find(' mex ')
|
|
20
|
-
fed.code.should == 'MEX'
|
|
21
|
-
fed.name.should == 'Mexico'
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "should return nil for an invalid code" do
|
|
25
|
-
Federation.find('XYZ').should be_nil
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context "#find using names" do
|
|
30
|
-
it "should find a federation given a valid name" do
|
|
31
|
-
fed = Federation.find('England')
|
|
32
|
-
fed.code.should == 'ENG'
|
|
33
|
-
fed.name.should == 'England'
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "should find a federation from name case insensitively" do
|
|
37
|
-
fed = Federation.find('franCE')
|
|
38
|
-
fed.code.should == 'FRA'
|
|
39
|
-
fed.name.should == 'France'
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "should not be fooled by irrelevant whitespace" do
|
|
43
|
-
fed = Federation.find(' united states of america ')
|
|
44
|
-
fed.code.should == 'USA'
|
|
45
|
-
fed.name.should == 'United States of America'
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "should return nil for an invalid name" do
|
|
49
|
-
Federation.find('Mordor').should be_nil
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context "#find using parts of names" do
|
|
54
|
-
it "should find a federation given a substring which is unique and at least 4 characters" do
|
|
55
|
-
fed = Federation.find('bosni')
|
|
56
|
-
fed.code.should == 'BIH'
|
|
57
|
-
fed.name.should == 'Bosnia and Herzegovina'
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "should not be fooled by irrelevant whitespace" do
|
|
61
|
-
fed = Federation.find(' arab EMIRATES ')
|
|
62
|
-
fed.code.should == 'UAE'
|
|
63
|
-
fed.name.should == 'United Arab Emirates'
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "should not find a federation if the substring matches more than one" do
|
|
67
|
-
Federation.find('land').should be_nil
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "should return nil for any string smaller in length than 3" do
|
|
71
|
-
Federation.find('ze').should be_nil
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
context "#find federations with alternative names" do
|
|
76
|
-
it "should find Macedonia multiple ways" do
|
|
77
|
-
Federation.find('MKD').name.should == 'Macedonia'
|
|
78
|
-
Federation.find('FYROM').name.should == 'Macedonia'
|
|
79
|
-
Federation.find('macedoni').name.should == 'Macedonia'
|
|
80
|
-
Federation.find('Macedonia').name.should == 'Macedonia'
|
|
81
|
-
Federation.find('former YUG Rep').name.should == 'Macedonia'
|
|
82
|
-
Federation.find('Republic of Macedonia').name.should == 'Macedonia'
|
|
83
|
-
Federation.find('former yugoslav republic').name.should == 'Macedonia'
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
context "#find with alternative inputs" do
|
|
88
|
-
it "should behave robustly with completely invalid inputs" do
|
|
89
|
-
Federation.find().should be_nil
|
|
90
|
-
Federation.find(nil).should be_nil
|
|
91
|
-
Federation.find('').should be_nil
|
|
92
|
-
Federation.find(1).should be_nil
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
context "#new is private" do
|
|
97
|
-
it "#new cannot be called directly" do
|
|
98
|
-
lambda { Federation.new('IRL', 'Ireland') }.should raise_error(/private method/)
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
context "documentation examples" do
|
|
103
|
-
it "should all be correct for valid input" do
|
|
104
|
-
Federation.find('IRL').name.should == 'Ireland'
|
|
105
|
-
Federation.find('IRL').code.should == 'IRL'
|
|
106
|
-
Federation.find('rUs').code.should == 'RUS'
|
|
107
|
-
Federation.find('ongoli').name.should == 'Mongolia'
|
|
108
|
-
Federation.find(' united states ').code.should == 'USA'
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it "should return nil for invalid input" do
|
|
112
|
-
Federation.find('ZYX').should be_nil
|
|
113
|
-
Federation.find('land').should be_nil
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
context "#menu" do
|
|
118
|
-
before(:all) do
|
|
119
|
-
@total = 174
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it "should return array of name-code pairs in order of name by default" do
|
|
123
|
-
menu = Federation.menu
|
|
124
|
-
menu.should have(@total).items
|
|
125
|
-
names = menu.map{|m| m.first}.join(',')
|
|
126
|
-
codes = menu.map{|m| m.last}.join(',')
|
|
127
|
-
names.index('Afghanistan').should == 0
|
|
128
|
-
names.index('Iraq,Ireland,Israel').should_not be_nil
|
|
129
|
-
codes.index('AFG').should == 0
|
|
130
|
-
codes.index('IRQ,IRL,ISR').should_not be_nil
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
it "should be configuarble to order the list by codes" do
|
|
134
|
-
menu = Federation.menu(:order => "code")
|
|
135
|
-
menu.should have(@total).items
|
|
136
|
-
names = menu.map{|m| m.first}.join(',')
|
|
137
|
-
codes = menu.map{|m| m.last}.join(',')
|
|
138
|
-
names.index('Afghanistan').should == 0
|
|
139
|
-
names.index('Ireland,Iraq,Iceland').should_not be_nil
|
|
140
|
-
codes.index('AFG').should == 0
|
|
141
|
-
codes.index('IRL,IRQ,ISL').should_not be_nil
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
it "should be configuarble to have a selected country at the top" do
|
|
145
|
-
menu = Federation.menu(:top => 'IRL')
|
|
146
|
-
menu.should have(@total).items
|
|
147
|
-
names = menu.map{|m| m.first}.join(',')
|
|
148
|
-
codes = menu.map{|m| m.last}.join(',')
|
|
149
|
-
names.index('Ireland,Afghanistan').should == 0
|
|
150
|
-
names.index('Iraq,Israel').should_not be_nil
|
|
151
|
-
codes.index('IRL,AFG').should == 0
|
|
152
|
-
codes.index('IRQ,ISR').should_not be_nil
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
it "should be configuarble to have 'None' entry at the top" do
|
|
156
|
-
menu = Federation.menu(:none => 'None')
|
|
157
|
-
menu.should have(@total + 1).items
|
|
158
|
-
names = menu.map{|m| m.first}.join(',')
|
|
159
|
-
codes = menu.map{|m| m.last}.join(',')
|
|
160
|
-
names.index('None,Afghanistan').should == 0
|
|
161
|
-
codes.index(',AFG').should == 0
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
it "should be able to handle multiple configuarations" do
|
|
165
|
-
menu = Federation.menu(:top => 'IRL', :order => 'code', :none => 'None')
|
|
166
|
-
menu.should have(@total + 1).items
|
|
167
|
-
names = menu.map{|m| m.first}.join(',')
|
|
168
|
-
codes = menu.map{|m| m.last}.join(',')
|
|
169
|
-
names.index('None,Ireland,Afghanistan').should == 0
|
|
170
|
-
names.index('Iraq,Iceland').should_not be_nil
|
|
171
|
-
codes.index(',IRL,AFG').should == 0
|
|
172
|
-
codes.index('IRQ,ISL').should_not be_nil
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
context "#codes" do
|
|
177
|
-
before(:all) do
|
|
178
|
-
@total = 174
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
it "should return array of codes ordered alphabetically" do
|
|
182
|
-
codes = Federation.codes
|
|
183
|
-
codes.should have(@total).items
|
|
184
|
-
all = codes.join(',')
|
|
185
|
-
all.index('AFG').should == 0
|
|
186
|
-
all.index('INA,IND,IRI,IRL,IRQ,ISL,ISR,ISV,ITA,IVB').should_not be_nil
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
end
|