uncharted 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/uncharted/country.rb +12 -1
- data/lib/uncharted/extensions/mongoid.rb +12 -18
- data/lib/uncharted/i18n.rb +4 -0
- data/lib/uncharted/locales/en.yml +250 -0
- data/lib/uncharted/locales/pt-BR.yml +251 -0
- data/lib/uncharted/territory.rb +5 -1
- data/lib/uncharted/version.rb +1 -1
- data/lib/uncharted.rb +2 -0
- data/test/country_test.rb +14 -8
- data/test/mongoid_test.rb +7 -8
- data/test/test_helper.rb +3 -0
- data/uncharted.gemspec +5 -3
- metadata +26 -12
data/lib/uncharted/country.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
|
1
3
|
module Uncharted
|
2
4
|
|
3
5
|
class Country
|
4
6
|
|
5
7
|
attr_reader :alpha2, :alpha3, :name
|
8
|
+
alias :code :alpha2
|
6
9
|
|
7
10
|
def initialize(alpha2, alpha3 = nil, name = nil)
|
8
11
|
@alpha2 = alpha2
|
@@ -10,7 +13,15 @@ module Uncharted
|
|
10
13
|
@name = name
|
11
14
|
self.class.data[alpha2] = self
|
12
15
|
end
|
16
|
+
|
17
|
+
def inspect
|
18
|
+
"#{@alpha2}: '#{@name}'"
|
19
|
+
end
|
13
20
|
|
21
|
+
def name(options = {})
|
22
|
+
I18n.t("countries.#{@alpha2}", {locale: options[:locale] || I18n.locale, default: @name})
|
23
|
+
end
|
24
|
+
|
14
25
|
def to_s
|
15
26
|
@alpha2
|
16
27
|
end
|
@@ -37,7 +48,7 @@ module Uncharted
|
|
37
48
|
def self.data
|
38
49
|
@data ||= {}
|
39
50
|
end
|
40
|
-
|
51
|
+
|
41
52
|
end
|
42
53
|
|
43
54
|
end
|
@@ -3,32 +3,26 @@
|
|
3
3
|
module Uncharted
|
4
4
|
|
5
5
|
class Country
|
6
|
+
include Mongoid::Fields::Serializable if defined? Mongoid
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def deserialize(alpha2)
|
11
|
-
alpha2 && Uncharted::Country.find(alpha2)
|
12
|
-
end
|
8
|
+
def deserialize(code)
|
9
|
+
code && Uncharted::Country.find(code)
|
10
|
+
end
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
end
|
12
|
+
def serialize(country)
|
13
|
+
country && country.code
|
17
14
|
end
|
18
15
|
end
|
19
16
|
|
20
17
|
class Territory
|
18
|
+
include Mongoid::Fields::Serializable if defined? Mongoid
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def deserialize(code)
|
26
|
-
code && Uncharted::Territory.find(code)
|
27
|
-
end
|
20
|
+
def deserialize(code)
|
21
|
+
code && Uncharted::Territory.find(code)
|
22
|
+
end
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
24
|
+
def serialize(territory)
|
25
|
+
territory && territory.code
|
32
26
|
end
|
33
27
|
end
|
34
28
|
|
@@ -0,0 +1,250 @@
|
|
1
|
+
en:
|
2
|
+
countries:
|
3
|
+
AC: Ascension
|
4
|
+
AD: Andorra
|
5
|
+
AE: United Arab Emirates
|
6
|
+
AF: Afghanistan
|
7
|
+
AG: Antigua and Barbuda
|
8
|
+
AI: Anguilla
|
9
|
+
AL: Albania
|
10
|
+
AM: Armenia
|
11
|
+
AN: Netherlands Antilles
|
12
|
+
AO: Angola
|
13
|
+
AQ: Antarctica
|
14
|
+
AR: Argentina
|
15
|
+
AS: American Samoa
|
16
|
+
AT: Austria
|
17
|
+
AU: Australia
|
18
|
+
AW: Aruba
|
19
|
+
AX: Aland
|
20
|
+
AZ: Azerbaijan
|
21
|
+
BA: Bosnia and Herzegovina
|
22
|
+
BB: Barbados
|
23
|
+
BD: Bangladesh
|
24
|
+
BE: Belgium
|
25
|
+
BF: Burkina Faso
|
26
|
+
BG: Bulgaria
|
27
|
+
BH: Bahrain
|
28
|
+
BI: Burundi
|
29
|
+
BJ: Benin
|
30
|
+
BM: Bermuda
|
31
|
+
BN: Brunei
|
32
|
+
BO: Bolivia
|
33
|
+
BR: Brazil
|
34
|
+
BS: Bahamas, The
|
35
|
+
BT: Bhutan
|
36
|
+
BV: Bouvet Island
|
37
|
+
BW: Botswana
|
38
|
+
BY: Belarus
|
39
|
+
BZ: Belize
|
40
|
+
CA: Canada
|
41
|
+
CC: Cocos Islands
|
42
|
+
CD: Congo DR
|
43
|
+
CF: Central Africa Republic
|
44
|
+
CG: Congo-Brazzaville
|
45
|
+
CH: Switzerland
|
46
|
+
CI: Ivory Coast
|
47
|
+
CK: Cook Islands
|
48
|
+
CL: Chile
|
49
|
+
CM: Cameroon
|
50
|
+
CN: China
|
51
|
+
CO: Colombia
|
52
|
+
CR: Costa Rica
|
53
|
+
CS: Kosovo
|
54
|
+
CU: Cuba
|
55
|
+
CV: Cape Verde
|
56
|
+
CX: Christmas Island
|
57
|
+
CY: Cyprus
|
58
|
+
CZ: Czech Republic
|
59
|
+
DE: Germany
|
60
|
+
DJ: Djibouti
|
61
|
+
DK: Denmark
|
62
|
+
DM: Dominica
|
63
|
+
DO: Dominican Republic
|
64
|
+
DZ: Algeria
|
65
|
+
EC: Ecuador
|
66
|
+
EE: Estonia
|
67
|
+
EG: Egypt
|
68
|
+
EH: Western Sahara
|
69
|
+
ER: Eritrea
|
70
|
+
ES: Spain
|
71
|
+
ET: Ethiopia
|
72
|
+
FI: Finland
|
73
|
+
FJ: Fiji
|
74
|
+
FK: Falkland Islands
|
75
|
+
FM: Micronesia
|
76
|
+
FO: Faroe Islands
|
77
|
+
FR: France
|
78
|
+
GA: Gabon
|
79
|
+
GB: United Kingdom
|
80
|
+
GD: Grenada
|
81
|
+
GE: Georgia
|
82
|
+
GF: French Guiana
|
83
|
+
GG: Guernsey
|
84
|
+
GH: Ghana
|
85
|
+
GI: Gibraltar
|
86
|
+
GL: Greenland
|
87
|
+
GM: Gambia, The
|
88
|
+
GN: Guinea
|
89
|
+
GP: Guadeloupe
|
90
|
+
GQ: Equatorial Guinea
|
91
|
+
GR: Greece
|
92
|
+
GS: South Georgia and the South Sandwich Islands
|
93
|
+
GT: Guatemala
|
94
|
+
GU: Guam
|
95
|
+
GW: Guinea-Bissau
|
96
|
+
GY: Guyana
|
97
|
+
HK: Hong Kong
|
98
|
+
HM: Heard Island and McDonald Islands
|
99
|
+
HN: Honduras
|
100
|
+
HR: Croatia
|
101
|
+
HT: Haiti
|
102
|
+
HU: Hungary
|
103
|
+
ID: Indonesia
|
104
|
+
IE: Ireland
|
105
|
+
IL: Israel
|
106
|
+
IM: Isle of Man
|
107
|
+
IN: India
|
108
|
+
IO: British Indian Ocean Territory
|
109
|
+
IQ: Iraq
|
110
|
+
IR: Iran
|
111
|
+
IS: Iceland
|
112
|
+
IT: Italy
|
113
|
+
JE: Jersey
|
114
|
+
JM: Jamaica
|
115
|
+
JO: Jordan
|
116
|
+
JP: Japan
|
117
|
+
KE: Kenya
|
118
|
+
KG: Kyrgyzstan
|
119
|
+
KH: Cambodia
|
120
|
+
KI: Kiribati
|
121
|
+
KM: Comoros
|
122
|
+
KN: Saint Kitts and Nevis
|
123
|
+
KP: North Korea
|
124
|
+
KR: South Korea
|
125
|
+
KW: Kuwait
|
126
|
+
KY: Cayman Islands
|
127
|
+
KZ: Kazakhstan
|
128
|
+
LA: Laos
|
129
|
+
LB: Lebanon
|
130
|
+
LC: Saint Lucia
|
131
|
+
LI: Liechtenstein
|
132
|
+
LK: Sri Lanka
|
133
|
+
LR: Liberia
|
134
|
+
LS: Lesotho
|
135
|
+
LT: Lithuania
|
136
|
+
LU: Luxembourg
|
137
|
+
LV: Latvia
|
138
|
+
LY: Libya
|
139
|
+
MA: Morocco
|
140
|
+
MC: Monaco
|
141
|
+
MD: Moldova
|
142
|
+
ME: Montenegro
|
143
|
+
MG: Madagascar
|
144
|
+
MH: Marshall Islands
|
145
|
+
MK: Macedonia
|
146
|
+
ML: Mali
|
147
|
+
MM: Myanmar (Burma)
|
148
|
+
MN: Mongolia
|
149
|
+
MO: Macau
|
150
|
+
MP: Northern Mariana Islands
|
151
|
+
MQ: Martinique
|
152
|
+
MR: Mauritania
|
153
|
+
MS: Montserrat
|
154
|
+
MT: Malta
|
155
|
+
MU: Mauritius
|
156
|
+
MV: Maldives
|
157
|
+
MW: Malawi
|
158
|
+
MX: Mexico
|
159
|
+
MY: Malaysia
|
160
|
+
MZ: Mozambique
|
161
|
+
NA: Namibia
|
162
|
+
NC: New Caledonia
|
163
|
+
NE: Niger
|
164
|
+
NF: Norfolk Island
|
165
|
+
NG: Nigeria
|
166
|
+
NI: Nicaragua
|
167
|
+
NL: Netherlands
|
168
|
+
NO: Norway
|
169
|
+
NP: Nepal
|
170
|
+
NR: Nauru
|
171
|
+
NU: Niue
|
172
|
+
NZ: New Zealand
|
173
|
+
OM: Oman
|
174
|
+
PA: Panama
|
175
|
+
PE: Peru
|
176
|
+
PF: French Polynesia
|
177
|
+
PF: Clipperton Island
|
178
|
+
PG: Papua New Guinea
|
179
|
+
PH: Philippines
|
180
|
+
PK: Pakistan
|
181
|
+
PL: Poland
|
182
|
+
PM: Saint Pierre and Miquelon
|
183
|
+
PN: Pitcairn Islands
|
184
|
+
PR: Puerto Rico
|
185
|
+
PS: Palestinian Territories
|
186
|
+
PT: Portugal
|
187
|
+
PW: Palau
|
188
|
+
PY: Paraguay
|
189
|
+
QA: Qatar
|
190
|
+
RE: Reunion
|
191
|
+
RO: Romania
|
192
|
+
RS: Serbia
|
193
|
+
RU: Russia
|
194
|
+
RW: Rwanda
|
195
|
+
SA: Saudi Arabia
|
196
|
+
SB: Solomon Islands
|
197
|
+
SC: Seychelles
|
198
|
+
SD: Sudan
|
199
|
+
SE: Sweden
|
200
|
+
SG: Singapore
|
201
|
+
SH: Saint Helena
|
202
|
+
SI: Slovenia
|
203
|
+
SJ: Svalbard
|
204
|
+
SK: Slovakia
|
205
|
+
SL: Sierra Leone
|
206
|
+
SM: San Marino
|
207
|
+
SN: Senegal
|
208
|
+
SO: Somalia
|
209
|
+
SR: Suriname
|
210
|
+
ST: Sao Tome and Principe
|
211
|
+
SV: El Salvador
|
212
|
+
SY: Syria
|
213
|
+
SZ: Swaziland
|
214
|
+
TA: Tristan da Cunha
|
215
|
+
TC: Turks and Caicos Islands
|
216
|
+
TD: Chad
|
217
|
+
TF: French Southern and Antarctic Lands
|
218
|
+
TG: Togo
|
219
|
+
TH: Thailand
|
220
|
+
TJ: Tajikistan
|
221
|
+
TK: Tokelau
|
222
|
+
TL: East Timor
|
223
|
+
TM: Turkmenistan
|
224
|
+
TN: Tunisia
|
225
|
+
TO: Tonga
|
226
|
+
TR: Turkey
|
227
|
+
TT: Trinidad and Tobago
|
228
|
+
TV: Tuvalu
|
229
|
+
TW: Taiwan
|
230
|
+
TZ: Tanzania
|
231
|
+
UA: Ukraine
|
232
|
+
UG: Uganda
|
233
|
+
UM: Midway Islands
|
234
|
+
US: United States
|
235
|
+
UY: Uruguay
|
236
|
+
UZ: Uzbekistan
|
237
|
+
VA: Vatican City
|
238
|
+
VC: Saint Vincent and the Grenadines
|
239
|
+
VE: Venezuela
|
240
|
+
VG: British Virgin Islands
|
241
|
+
VI: U.S. Virgin Islands
|
242
|
+
VN: Vietnam
|
243
|
+
VU: Vanuatu
|
244
|
+
WF: Wallis and Futuna
|
245
|
+
WS: Samoa
|
246
|
+
YE: Yemen
|
247
|
+
YT: Mayotte
|
248
|
+
ZA: South Africa
|
249
|
+
ZM: Zambia
|
250
|
+
ZW: Zimbabwe
|
@@ -0,0 +1,251 @@
|
|
1
|
+
pt-BR:
|
2
|
+
countries:
|
3
|
+
AC: Ascenção
|
4
|
+
AD: Andorra
|
5
|
+
AE: United Arab Emirates
|
6
|
+
AF: Afghanistan
|
7
|
+
AG: Antigua and Barbuda
|
8
|
+
AI: Anguilla
|
9
|
+
AL: Albania
|
10
|
+
AM: Armenia
|
11
|
+
AN: Netherlands Antilles
|
12
|
+
AO: Angola
|
13
|
+
AQ: Antarctica
|
14
|
+
AR: Argentina
|
15
|
+
AS: American Samoa
|
16
|
+
AT: Austria
|
17
|
+
AU: Australia
|
18
|
+
AW: Aruba
|
19
|
+
AX: Aland
|
20
|
+
AZ: Azerbaijan
|
21
|
+
BA: Bosnia and Herzegovina
|
22
|
+
BB: Barbados
|
23
|
+
BD: Bangladesh
|
24
|
+
BE: Belgium
|
25
|
+
BF: Burkina Faso
|
26
|
+
BG: Bulgaria
|
27
|
+
BH: Bahrain
|
28
|
+
BI: Burundi
|
29
|
+
BJ: Benin
|
30
|
+
BM: Bermuda
|
31
|
+
BN: Brunei
|
32
|
+
BO: Bolivia
|
33
|
+
BR: Brasil
|
34
|
+
BS: Bahamas, The
|
35
|
+
BT: Bhutan
|
36
|
+
BV: Bouvet Island
|
37
|
+
BW: Botswana
|
38
|
+
BY: Belarus
|
39
|
+
BZ: Belize
|
40
|
+
CA: Canada
|
41
|
+
CC: Cocos Islands
|
42
|
+
CD: Congo DR
|
43
|
+
CF: Central Africa Republic
|
44
|
+
CG: Congo-Brazzaville
|
45
|
+
CH: Switzerland
|
46
|
+
CI: Ivory Coast
|
47
|
+
CK: Cook Islands
|
48
|
+
CL: Chile
|
49
|
+
CM: Cameroon
|
50
|
+
CN: China
|
51
|
+
CO: Colombia
|
52
|
+
CR: Costa Rica
|
53
|
+
CS: Kosovo
|
54
|
+
CU: Cuba
|
55
|
+
CV: Cape Verde
|
56
|
+
CX: Christmas Island
|
57
|
+
CY: Cyprus
|
58
|
+
CZ: Czech Republic
|
59
|
+
DE: Germany
|
60
|
+
DJ: Djibouti
|
61
|
+
DK: Denmark
|
62
|
+
DM: Dominica
|
63
|
+
DO: Dominican Republic
|
64
|
+
DZ: Algeria
|
65
|
+
EC: Ecuador
|
66
|
+
EE: Estonia
|
67
|
+
EG: Egypt
|
68
|
+
EH: Western Sahara
|
69
|
+
ER: Eritrea
|
70
|
+
ES: Spain
|
71
|
+
ET: Ethiopia
|
72
|
+
FI: Finland
|
73
|
+
FJ: Fiji
|
74
|
+
FK: Falkland Islands
|
75
|
+
FM: Micronesia
|
76
|
+
FO: Faroe Islands
|
77
|
+
FR: France
|
78
|
+
GA: Gabon
|
79
|
+
GB: United Kingdom
|
80
|
+
GD: Grenada
|
81
|
+
GE: Georgia
|
82
|
+
GF: French Guiana
|
83
|
+
GG: Guernsey
|
84
|
+
GH: Ghana
|
85
|
+
GI: Gibraltar
|
86
|
+
GL: Greenland
|
87
|
+
GM: Gambia, The
|
88
|
+
GN: Guinea
|
89
|
+
GP: Guadeloupe
|
90
|
+
GQ: Equatorial Guinea
|
91
|
+
GR: Greece
|
92
|
+
GS: South Georgia and the South Sandwich Islands
|
93
|
+
GT: Guatemala
|
94
|
+
GU: Guam
|
95
|
+
GW: Guinea-Bissau
|
96
|
+
GY: Guyana
|
97
|
+
HK: Hong Kong
|
98
|
+
HM: Heard Island and McDonald Islands
|
99
|
+
HN: Honduras
|
100
|
+
HR: Croatia
|
101
|
+
HT: Haiti
|
102
|
+
HU: Hungary
|
103
|
+
ID: Indonesia
|
104
|
+
IE: Ireland
|
105
|
+
IL: Israel
|
106
|
+
IM: Isle of Man
|
107
|
+
IN: India
|
108
|
+
IO: British Indian Ocean Territory
|
109
|
+
IQ: Iraq
|
110
|
+
IR: Iran
|
111
|
+
IS: Iceland
|
112
|
+
IT: Italy
|
113
|
+
JE: Jersey
|
114
|
+
JM: Jamaica
|
115
|
+
JO: Jordan
|
116
|
+
JP: Japan
|
117
|
+
KE: Kenya
|
118
|
+
KG: Kyrgyzstan
|
119
|
+
KH: Cambodia
|
120
|
+
KI: Kiribati
|
121
|
+
KM: Comoros
|
122
|
+
KN: Saint Kitts and Nevis
|
123
|
+
KP: North Korea
|
124
|
+
KR: South Korea
|
125
|
+
KW: Kuwait
|
126
|
+
KY: Cayman Islands
|
127
|
+
KZ: Kazakhstan
|
128
|
+
LA: Laos
|
129
|
+
LB: Lebanon
|
130
|
+
LC: Saint Lucia
|
131
|
+
LI: Liechtenstein
|
132
|
+
LK: Sri Lanka
|
133
|
+
LR: Liberia
|
134
|
+
LS: Lesotho
|
135
|
+
LT: Lithuania
|
136
|
+
LU: Luxembourg
|
137
|
+
LV: Latvia
|
138
|
+
LY: Libya
|
139
|
+
MA: Morocco
|
140
|
+
MC: Monaco
|
141
|
+
MD: Moldova
|
142
|
+
ME: Montenegro
|
143
|
+
MG: Madagascar
|
144
|
+
MH: Marshall Islands
|
145
|
+
MK: Macedonia
|
146
|
+
ML: Mali
|
147
|
+
MM: Myanmar (Burma)
|
148
|
+
MN: Mongolia
|
149
|
+
MO: Macau
|
150
|
+
MP: Northern Mariana Islands
|
151
|
+
MQ: Martinique
|
152
|
+
MR: Mauritania
|
153
|
+
MS: Montserrat
|
154
|
+
MT: Malta
|
155
|
+
MU: Mauritius
|
156
|
+
MV: Maldives
|
157
|
+
MW: Malawi
|
158
|
+
MX: Mexico
|
159
|
+
MY: Malaysia
|
160
|
+
MZ: Mozambique
|
161
|
+
NA: Namibia
|
162
|
+
NC: New Caledonia
|
163
|
+
NE: Niger
|
164
|
+
NF: Norfolk Island
|
165
|
+
NG: Nigeria
|
166
|
+
NI: Nicaragua
|
167
|
+
NL: Netherlands
|
168
|
+
NO: Norway
|
169
|
+
NP: Nepal
|
170
|
+
NR: Nauru
|
171
|
+
NU: Niue
|
172
|
+
NZ: New Zealand
|
173
|
+
OM: Oman
|
174
|
+
PA: Panama
|
175
|
+
PE: Peru
|
176
|
+
PF: French Polynesia
|
177
|
+
PF: Clipperton Island
|
178
|
+
PG: Papua New Guinea
|
179
|
+
PH: Philippines
|
180
|
+
PK: Pakistan
|
181
|
+
PL: Poland
|
182
|
+
PM: Saint Pierre and Miquelon
|
183
|
+
PN: Pitcairn Islands
|
184
|
+
PR: Puerto Rico
|
185
|
+
PS: Palestinian Territories
|
186
|
+
PT: Portugal
|
187
|
+
PW: Palau
|
188
|
+
PY: Paraguay
|
189
|
+
QA: Qatar
|
190
|
+
RE: Reunion
|
191
|
+
RO: Romania
|
192
|
+
RS: Serbia
|
193
|
+
RU: Russia
|
194
|
+
RW: Rwanda
|
195
|
+
SA: Saudi Arabia
|
196
|
+
SB: Solomon Islands
|
197
|
+
SC: Seychelles
|
198
|
+
SD: Sudan
|
199
|
+
SE: Sweden
|
200
|
+
SG: Singapore
|
201
|
+
SH: Saint Helena
|
202
|
+
SI: Slovenia
|
203
|
+
SJ: Svalbard
|
204
|
+
SK: Slovakia
|
205
|
+
SL: Sierra Leone
|
206
|
+
SM: San Marino
|
207
|
+
SN: Senegal
|
208
|
+
SO: Somalia
|
209
|
+
SR: Suriname
|
210
|
+
ST: Sao Tome and Principe
|
211
|
+
SV: El Salvador
|
212
|
+
SY: Syria
|
213
|
+
SZ: Swaziland
|
214
|
+
TA: Tristan da Cunha
|
215
|
+
TC: Turks and Caicos Islands
|
216
|
+
TD: Chad
|
217
|
+
TF: French Southern and Antarctic Lands
|
218
|
+
TG: Togo
|
219
|
+
TH: Thailand
|
220
|
+
TJ: Tajikistan
|
221
|
+
TK: Tokelau
|
222
|
+
TL: East Timor
|
223
|
+
TM: Turkmenistan
|
224
|
+
TN: Tunisia
|
225
|
+
TO: Tonga
|
226
|
+
TR: Turkey
|
227
|
+
TT: Trinidad and Tobago
|
228
|
+
TV: Tuvalu
|
229
|
+
TW: Taiwan
|
230
|
+
TZ: Tanzania
|
231
|
+
UA: Ukraine
|
232
|
+
UG: Uganda
|
233
|
+
UM: Midway Islands
|
234
|
+
US: United States
|
235
|
+
UY: Uruguay
|
236
|
+
UZ: Uzbekistan
|
237
|
+
VA: Vatican City
|
238
|
+
VC: Saint Vincent and the Grenadines
|
239
|
+
VE: Venezuela
|
240
|
+
VG: British Virgin Islands
|
241
|
+
VI: U.S. Virgin Islands
|
242
|
+
VN: Vietnam
|
243
|
+
VU: Vanuatu
|
244
|
+
WF: Wallis and Futuna
|
245
|
+
WS: Samoa
|
246
|
+
YE: Yemen
|
247
|
+
YT: Mayotte
|
248
|
+
ZA: South Africa
|
249
|
+
ZM: Zambia
|
250
|
+
ZW: Zimbabwe
|
251
|
+
|
data/lib/uncharted/territory.rb
CHANGED
@@ -32,7 +32,7 @@ module Uncharted
|
|
32
32
|
|
33
33
|
class Territory
|
34
34
|
|
35
|
-
attr_reader :abbr, :code, :country, :country_code, :
|
35
|
+
attr_reader :abbr, :code, :country, :country_code, :type
|
36
36
|
|
37
37
|
def initialize(code, type, name)
|
38
38
|
@code = code
|
@@ -44,6 +44,10 @@ module Uncharted
|
|
44
44
|
@country.subdivisions << self if @country
|
45
45
|
end
|
46
46
|
|
47
|
+
def name(options = {})
|
48
|
+
I18n.t("territories.#{@country_code}#{@abbr}", {locale: options[:locale] || I18n.locale}, default: @name)
|
49
|
+
end
|
50
|
+
|
47
51
|
def to_s
|
48
52
|
@abbr
|
49
53
|
end
|
data/lib/uncharted/version.rb
CHANGED
data/lib/uncharted.rb
CHANGED
data/test/country_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'uncharted'
|
4
2
|
|
3
|
+
require 'test_helper'
|
5
4
|
|
6
5
|
class TestCountry < MiniTest::Unit::TestCase
|
7
6
|
|
@@ -13,7 +12,7 @@ class TestCountry < MiniTest::Unit::TestCase
|
|
13
12
|
assert @br, "BR must exist"
|
14
13
|
assert_equal 'BR', @br.alpha2
|
15
14
|
assert_equal 'BRA', @br.alpha3
|
16
|
-
assert_equal 'Brazil', @br.name
|
15
|
+
assert_equal 'Brazil', @br.name(locale: :en)
|
17
16
|
end
|
18
17
|
|
19
18
|
def test_country_find
|
@@ -38,20 +37,27 @@ class TestCountry < MiniTest::Unit::TestCase
|
|
38
37
|
assert_equal 27, @br.subdivisions.count
|
39
38
|
assert @br.territories.empty?
|
40
39
|
|
41
|
-
assert_equal 'Paraná',
|
42
|
-
assert_equal 'PR',
|
43
|
-
assert_equal 'PR',
|
40
|
+
assert_equal 'Paraná', Territory.find('BR-PR').name
|
41
|
+
assert_equal 'PR', Territory.find('BR-PR').abbr
|
42
|
+
assert_equal 'PR', Territory.find('BR-PR').to_s
|
44
43
|
end
|
45
44
|
|
46
45
|
def test_classes
|
47
46
|
assert_equal Country, Uncharted::Country
|
48
47
|
assert_equal Territory, Uncharted::Territory
|
49
|
-
assert_equal Country::Field, Uncharted::Country::Field
|
50
|
-
assert_equal Territory::Field, Uncharted::Territory::Field
|
51
48
|
end
|
52
49
|
|
53
50
|
def test_country_collection
|
54
51
|
assert_equal 247, Country.countries.count
|
55
52
|
end
|
53
|
+
|
54
|
+
def test_translation
|
55
|
+
assert_equal "Brazil", @br.name(locale: :en)
|
56
|
+
assert_equal "Brasil", @br.name(locale: 'pt-BR')
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_inspection
|
60
|
+
assert_equal "BR: 'Brazil'", @br.inspect
|
61
|
+
end
|
56
62
|
|
57
63
|
end
|
data/test/mongoid_test.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'test_helper'
|
3
|
-
require 'uncharted'
|
4
3
|
|
5
4
|
class TestMongoidAdapter < MiniTest::Unit::TestCase
|
6
5
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
6
|
+
def test_serializers
|
7
|
+
assert_equal 'BR', Country.allocate.serialize(Country.find('BR'))
|
8
|
+
assert_equal 'BR-PR', Territory.allocate.serialize(Territory.find('BR-PR'))
|
10
9
|
end
|
11
|
-
|
12
|
-
def
|
13
|
-
assert_equal 'BR',
|
14
|
-
assert_equal 'BR-PR',
|
10
|
+
|
11
|
+
def test_deserializers
|
12
|
+
assert_equal Country.find('BR'), Country.allocate.deserialize('BR')
|
13
|
+
assert_equal Territory.find('BR-PR'), Territory.allocate.deserialize('BR-PR')
|
15
14
|
end
|
16
15
|
|
17
16
|
end
|
data/test/test_helper.rb
CHANGED
data/uncharted.gemspec
CHANGED
@@ -20,11 +20,13 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
21
21
|
|
22
22
|
s.required_ruby_version = '>= 1.9'
|
23
|
-
|
24
|
-
s.
|
23
|
+
|
24
|
+
s.add_dependency 'i18n'
|
25
|
+
|
26
|
+
s.add_development_dependency 'minitest'
|
25
27
|
s.add_development_dependency 'purdytest' # colored tests for minitest https://github.com/tenderlove/purdytest
|
26
28
|
s.add_development_dependency 'simplecov'
|
27
29
|
s.add_development_dependency 'simplecov-rcov'
|
28
|
-
s.add_development_dependency 'yard'
|
30
|
+
s.add_development_dependency 'yard'
|
29
31
|
|
30
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uncharted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10
|
12
|
+
date: 2011-11-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: i18n
|
16
|
+
requirement: &2160716480 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2160716480
|
14
25
|
- !ruby/object:Gem::Dependency
|
15
26
|
name: minitest
|
16
|
-
requirement: &
|
27
|
+
requirement: &2160737840 !ruby/object:Gem::Requirement
|
17
28
|
none: false
|
18
29
|
requirements:
|
19
30
|
- - ! '>='
|
@@ -21,10 +32,10 @@ dependencies:
|
|
21
32
|
version: '0'
|
22
33
|
type: :development
|
23
34
|
prerelease: false
|
24
|
-
version_requirements: *
|
35
|
+
version_requirements: *2160737840
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: purdytest
|
27
|
-
requirement: &
|
38
|
+
requirement: &2160737180 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *2160737180
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: simplecov
|
38
|
-
requirement: &
|
49
|
+
requirement: &2160736080 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *2160736080
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: simplecov-rcov
|
49
|
-
requirement: &
|
60
|
+
requirement: &2160734700 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *2160734700
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: yard
|
60
|
-
requirement: &
|
71
|
+
requirement: &2160733560 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ! '>='
|
@@ -65,7 +76,7 @@ dependencies:
|
|
65
76
|
version: '0'
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *2160733560
|
69
80
|
description: Provide ISO 3166 codes and english name for countries and their political
|
70
81
|
divisions
|
71
82
|
email:
|
@@ -87,6 +98,9 @@ files:
|
|
87
98
|
- lib/uncharted/data/countries.rb
|
88
99
|
- lib/uncharted/extensions/mongoid.rb
|
89
100
|
- lib/uncharted/extensions/rails.rb
|
101
|
+
- lib/uncharted/i18n.rb
|
102
|
+
- lib/uncharted/locales/en.yml
|
103
|
+
- lib/uncharted/locales/pt-BR.yml
|
90
104
|
- lib/uncharted/territory.rb
|
91
105
|
- lib/uncharted/version.rb
|
92
106
|
- test/country_test.rb
|