decoder 0.5.1 → 0.6.4

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.
@@ -1,31 +1,20 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class CountriesTest < Test::Unit::TestCase
4
+ should "print '#<#class>" do
5
+ assert_equal "#<Decoder::Countries>", Decoder::Countries.new.inspect
6
+ end
7
+
4
8
  context "English" do
5
9
  setup do
6
- Decoder.i18n = :eng
7
- end
8
-
9
- context "Loading the YAML" do
10
- setup do
11
- @countries = Decoder::Countries.new
12
- end
13
-
14
- should "load yaml/countries/eng.yml" do
15
- assert_match /eng.yml/, @countries.yaml_file_name
16
- end
17
-
18
- should "set the #countries with the country data" do
19
- YAML.expects(:load_file).returns({:US => "United States"})
20
- @countries.load_yaml
21
- assert "United States", @countries.countries[:US]
22
- end
10
+ Decoder.i18n = :en
23
11
  end
24
12
 
25
13
  context "a new object" do
26
14
  should "load the yaml" do
27
- Decoder::Countries.any_instance.expects(:load_yaml)
28
- Decoder::Countries.new
15
+ Decoder.expects(:load_yaml).returns({:en => {"US" => {:name => "United States", :states => {"MA" => "Massachusetts"}}}})
16
+ countries = Decoder::Countries.new
17
+ assert_not_nil countries.countries
29
18
  end
30
19
  end
31
20
 
@@ -6,32 +6,17 @@ class CountryTest < Test::Unit::TestCase
6
6
  assert_contains Decoder::State.included_modules, CommonMethods
7
7
  end
8
8
 
9
- context "English" do
9
+ context "English for US" do
10
10
  setup do
11
- Decoder.i18n = :eng
11
+ Decoder.i18n = :en
12
12
  end
13
13
 
14
- context "Loading the YAML" do
15
- setup do
16
- @country = Decoder::Country.new(:code => "US", :name => "United States")
17
- end
18
-
19
- should "load yaml/states/us/eng.yml" do
20
- assert_match /eng.yml/, @country.yaml_file_name
21
- assert_match /us/, @country.yaml_file_name
22
- end
23
-
24
- should "set the #states with the US state data" do
25
- YAML.expects(:load_file).returns({:MA => "Massachusetts"})
26
- @country.load_yaml
27
- assert "Massachusetts", @country.states[:MA]
28
- end
29
- end
30
-
31
- context "a new object" do
14
+ context "A new country" do
32
15
  should "load the yaml" do
33
- Decoder::Country.any_instance.expects(:load_yaml)
34
- Decoder::Country.new(:code => "US", :name => "United States")
16
+ Decoder.expects(:load_yaml).returns({:en => {"US" => {:name => "United States", :states => {"MA" => "Massachusetts"}}}})
17
+
18
+ country = Decoder::Country.new(:code => "US", :name => "United States")
19
+ assert_not_nil country.states
35
20
  end
36
21
  end
37
22
 
@@ -61,21 +46,31 @@ class CountryTest < Test::Unit::TestCase
61
46
  end
62
47
 
63
48
  end
64
-
65
- end
66
-
67
- context "#states aliases" do
68
- setup do
69
- @country = Decoder::Country.new(:code => "US", :name => "United States")
70
- end
71
-
72
- should "be equal for #states and #provinces" do
73
- assert_equal @country.states, @country.provinces
49
+
50
+ context "#states" do
51
+ setup do
52
+ @country = Decoder::Country.new(:code => "US", :name => "United States")
53
+ end
54
+
55
+ should "a hash of states" do
56
+ assert_equal "Massachusetts", @country.states["MA"]
57
+ end
58
+
59
+ context "aliases" do
60
+ should "be equal for #states and #counties" do
61
+ assert_equal @country.states, @country.counties
62
+ end
63
+
64
+ should "be equal for #states and #provinces" do
65
+ assert_equal @country.states, @country.provinces
66
+ end
67
+
68
+ should "be equal for #states and #territories" do
69
+ assert_equal @country.states, @country.territories
70
+ end
71
+ end
74
72
  end
75
73
 
76
- should "be equal for #states and #territories" do
77
- assert_equal @country.states, @country.territories
78
- end
79
74
  end
80
75
 
81
76
  end
data/test/decoder_test.rb CHANGED
@@ -3,12 +3,28 @@ require 'test_helper'
3
3
  class DecoderTest < Test::Unit::TestCase
4
4
  context "i18n" do
5
5
  should "default to :eng" do
6
- assert_equal :eng, Decoder.i18n
6
+ assert_equal :en, Decoder.i18n
7
7
  end
8
8
 
9
- should "set the Internationalization code to :gla (Gaelic)" do
10
- Decoder.i18n = :gla
11
- assert_equal :gla, Decoder.i18n
9
+ should "set the Internationalization code to :de (German)" do
10
+ Decoder.i18n = :de
11
+ assert_equal :de, Decoder.i18n
12
+ assert_nil Decoder.class_eval { @locale }
13
+ end
14
+ end
15
+
16
+ context "File loading" do
17
+ setup do
18
+ Decoder.locale = nil
19
+ end
20
+
21
+ should "only load once" do
22
+ YAML.expects(:load_file).returns({:en => {"US" => {:name => "United States",
23
+ :states => {"MA" => "Massachusetts"}}}})
24
+ locale = Decoder.locale
25
+ Decoder.locale
26
+ Decoder::Countries.new
27
+ Decoder::Country.new(:code => "US", :name => "United States")
12
28
  end
13
29
  end
14
30
  end
@@ -8,7 +8,7 @@ class StateTest < Test::Unit::TestCase
8
8
 
9
9
  context "English" do
10
10
  setup do
11
- Decoder.i18n = :eng
11
+ Decoder.i18n = :en
12
12
  end
13
13
 
14
14
  context "Getters" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cardarella
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-01 00:00:00 -04:00
12
+ date: 2009-09-07 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,14 +40,11 @@ files:
40
40
  - VERSION
41
41
  - decoder.gemspec
42
42
  - lib/common_methods.rb
43
- - lib/countries/countries.rb
44
- - lib/countries/country.rb
45
43
  - lib/decoder.rb
46
- - lib/i18n/countries/eng.yml
47
- - lib/i18n/states/au/eng.yml
48
- - lib/i18n/states/ca/eng.yml
49
- - lib/i18n/states/us/eng.yml
50
- - lib/states/state.rb
44
+ - lib/decoder/countries.rb
45
+ - lib/decoder/country.rb
46
+ - lib/decoder/state.rb
47
+ - lib/locales/en.yml
51
48
  - test/common_methods_test.rb
52
49
  - test/countries/countries_test.rb
53
50
  - test/countries/country_test.rb
@@ -1,27 +0,0 @@
1
- module Decoder
2
- class Countries
3
- attr_accessor :countries
4
-
5
- def initialize
6
- self.load_yaml
7
- end
8
-
9
- def load_yaml
10
- self.countries = YAML.load_file(yaml_file_name)
11
- end
12
-
13
- def yaml_file_name
14
- "#{File.dirname(__FILE__)}/../i18n/countries/#{Decoder.i18n}.yml"
15
- end
16
-
17
- def [](_code)
18
- _code = _code.to_s.upcase
19
- country = countries[_code]
20
- Decoder::Country.new(:code => _code, :name => country)
21
- end
22
-
23
- def self.[](_code)
24
- self.new[_code]
25
- end
26
- end
27
- end
@@ -1,252 +0,0 @@
1
- ---
2
- UY: Uruguay
3
- NP: Nepal
4
- BS: Bahamas
5
- HT: Haiti
6
- LK: Sri Lanka
7
- SE: Sweden
8
- DZ: Algeria
9
- TW: Taiwan
10
- GU: Guam
11
- NC: New Caledonia
12
- BH: Bahrain
13
- RS: Serbia
14
- CY: Cyprus
15
- KW: Kuwait
16
- MU: Mauritius
17
- AZ: Azerbaijan
18
- TM: Turkmenistan
19
- GM: Gambia
20
- ZR: Zaire
21
- KG: Kyrgyzstan
22
- PS: Palestinian Territory, Occupied
23
- CN: China
24
- TC: Turks and Caicos Islands
25
- GB: Great Britain (UK)
26
- MN: Mongolia
27
- AQ: Antarctica
28
- WF: Wallis and Futuna Islands
29
- PG: Papua New Guinea
30
- CF: Central African Republic
31
- IS: Iceland
32
- MD: Moldova
33
- AF: Afghanistan
34
- SO: Somalia
35
- FJ: Fiji
36
- VA: Vatican City State (Holy See)
37
- ID: Indonesia
38
- NT: Neutral Zone
39
- BV: Bouvet Island
40
- SH: St. Helena
41
- EE: Estonia
42
- LS: Lesotho
43
- UA: Ukraine
44
- NF: Norfolk Island
45
- BJ: Benin
46
- GY: Guyana
47
- KZ: Kazakhstan
48
- RW: Rwanda
49
- DE: Germany
50
- GP: Guadeloupe
51
- MW: Malawi
52
- BB: Barbados
53
- TO: Tonga
54
- CR: Costa Rica
55
- KI: Kiribati
56
- PW: Palau
57
- AS: American Samoa
58
- TF: French Southern Territories
59
- GE: Georgia
60
- IO: British Indian Ocean Territory
61
- MP: Northern Mariana Islands
62
- YE: Yemen
63
- PK: Pakistan
64
- CH: Switzerland
65
- JE: Jersey
66
- MG: Madagascar
67
- AI: Anguilla
68
- ST: Sao Tome and Principe
69
- FM: Micronesia
70
- VE: Venezuela
71
- IL: Israel
72
- NZ: New Zealand (Aotearoa)
73
- BY: Belarus
74
- SJ: Svalbard & Jan Mayen Islands
75
- EH: Western Sahara
76
- LU: Luxembourg
77
- UK: United Kingdom
78
- NI: Nicaragua
79
- BN: Brunei Darussalam
80
- HM: Heard and McDonald Islands
81
- LB: Lebanon
82
- SB: Solomon Islands
83
- DK: Denmark
84
- TR: Turkey
85
- GR: Greece
86
- MY: Malaysia
87
- BE: Belgium
88
- QA: Qatar
89
- CU: Cuba
90
- KN: Saint Kitts and Nevis
91
- MR: Mauritania
92
- AU: Australia
93
- TH: Thailand
94
- GH: Ghana
95
- YU: Yugoslavia (former)
96
- JO: Jordan
97
- PM: St. Pierre and Miquelon
98
- CK: Cook Islands
99
- SV: El Salvador
100
- FR: France
101
- MK: F.Y.R.O.M. (Macedonia)
102
- AM: Armenia
103
- VI: Virgin Islands (U.S.)
104
- PA: Panama
105
- CA: Canada
106
- IN: India
107
- LY: Libya
108
- AC: Ascension Island
109
- SL: Sierra Leone
110
- ES: Spain
111
- US: United States
112
- HR: Croatia (Hrvatska)
113
- NO: Norway
114
- BR: Brazil
115
- SD: Sudan
116
- DO: Dominican Republic
117
- LI: Liechtenstein
118
- TV: Tuvalu
119
- NA: Namibia
120
- BG: Bulgaria
121
- GT: Guatemala
122
- KR: Korea (South)
123
- RO: Romania
124
- CX: Christmas Island
125
- TK: Tokelau
126
- GL: Greenland
127
- MT: Malta
128
- AX: Aland Islands
129
- ZM: Zambia
130
- PR: Puerto Rico
131
- CM: Cameroon
132
- KE: Kenya
133
- MM: Myanmar
134
- AO: Angola
135
- SZ: Swaziland
136
- GA: Gabon
137
- VU: Vanuatu
138
- IR: Iran
139
- PF: French Polynesia
140
- CD: Congo, Democratic Republic
141
- FI: Finland
142
- MC: Monaco
143
- AE: United Arab Emirates
144
- SN: Senegal
145
- UZ: Uzbekistan
146
- BT: Bhutan
147
- HU: Hungary
148
- NR: Nauru
149
- SG: Singapore
150
- EC: Ecuador
151
- LR: Liberia
152
- TZ: Tanzania
153
- NE: Niger
154
- BI: Burundi
155
- GW: Guinea-Bissau
156
- KY: Cayman Islands
157
- RU: Russian Federation
158
- CZ: Czech Republic
159
- TN: Tunisia
160
- GN: Guinea
161
- MV: Maldives
162
- BA: Bosnia and Herzegovina
163
- ZW: Zimbabwe
164
- PT: Portugal
165
- CO: Colombia
166
- KH: Cambodia
167
- MO: Macau
168
- AR: Argentina
169
- TD: Chad
170
- GD: Grenada
171
- WS: Samoa
172
- IT: Italy
173
- PH: Philippines
174
- CG: Congo
175
- SR: Suriname
176
- FK: Falkland Islands (Malvinas)
177
- ME: Montenegro
178
- AG: Antigua and Barbuda
179
- VC: Saint Vincent & the Grenadines
180
- NU: Niue
181
- BW: Botswana
182
- IE: Ireland
183
- LT: Lithuania
184
- SI: Slovenia
185
- EG: Egypt
186
- UG: Uganda
187
- HK: Hong Kong
188
- NG: Nigeria
189
- BM: Bermuda
190
- SA: Saudi Arabia
191
- DJ: Djibouti
192
- LA: Laos
193
- TP: East Timor
194
- MX: Mexico
195
- BD: Bangladesh
196
- GQ: Equatorial Guinea
197
- KM: Comoros
198
- PY: Paraguay
199
- CS: Czechoslovakia (former)
200
- TG: Togo
201
- GF: French Guiana
202
- MQ: Martinique
203
- AT: Austria
204
- YT: Mayotte
205
- PL: Poland
206
- CI: Cote D'Ivoire (Ivory Coast)
207
- JM: Jamaica
208
- MH: Marshall Islands
209
- AL: Albania
210
- SU: USSR (former)
211
- FO: Faroe Islands
212
- VG: British Virgin Islands
213
- IM: Isle of Man
214
- OM: Oman
215
- BZ: Belize
216
- SK: Slovak Republic
217
- ER: Eritrea
218
- LV: Latvia
219
- UM: US Minor Outlying Islands
220
- NL: Netherlands
221
- BO: Bolivia
222
- HN: Honduras
223
- LC: Saint Lucia
224
- SC: Seychelles
225
- DM: Dominica
226
- TT: Trinidad and Tobago
227
- GS: S. Georgia and S. Sandwich Isls.
228
- MZ: Mozambique
229
- BF: Burkina Faso
230
- CV: Cape Verde
231
- KP: Korea (North)
232
- RE: Reunion
233
- AW: Aruba
234
- TJ: Tajikistan
235
- GI: Gibraltar
236
- MS: Montserrat
237
- ZA: South Africa
238
- PN: Pitcairn
239
- CL: Chile
240
- JP: Japan
241
- ML: Mali
242
- AN: Netherlands Antilles
243
- SY: Syria
244
- FX: France, Metropolitan
245
- VN: Viet Nam
246
- IQ: Iraq
247
- PE: Peru
248
- CC: Cocos (Keeling) Islands
249
- SM: San Marino
250
- ET: Ethiopia
251
- MA: Morocco
252
- AD: Andorra