bcardarella-coder 0.2.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/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +33 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/coder.gemspec +65 -0
- data/lib/coder.rb +13 -0
- data/lib/countries/countries.rb +28 -0
- data/lib/countries/country.rb +30 -0
- data/lib/i18n/countries/eng.yml +252 -0
- data/lib/i18n/states/us/eng.yml +2 -0
- data/lib/states/state.rb +14 -0
- data/test/coder_test.rb +14 -0
- data/test/countries/countries_test.rb +93 -0
- data/test/countries/country_test.rb +70 -0
- data/test/states/state_test.rb +28 -0
- data/test/test_helper.rb +12 -0
- metadata +84 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Brian Cardarella
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
= coder
|
2
|
+
|
3
|
+
= Usage
|
4
|
+
|
5
|
+
>> Coder.i18n = :eng
|
6
|
+
>> country = Coder::Countries[:US]
|
7
|
+
>> country.to_s
|
8
|
+
=> "United States"
|
9
|
+
>> state = country[:MA]
|
10
|
+
>> state.to_s
|
11
|
+
=> "Massachusetts"
|
12
|
+
|
13
|
+
Currently the yaml files are still quite incomplete. Please fork and populate!
|
14
|
+
|
15
|
+
= i18n
|
16
|
+
When adding a new language please use the ISO 639-2 Code 3-letter standard.
|
17
|
+
You can find the appropriate code for a given language here:
|
18
|
+
http://www.loc.gov/standards/iso639-2/php/code_list.php
|
19
|
+
|
20
|
+
== Note on Patches/Pull Requests
|
21
|
+
|
22
|
+
* Fork the project.
|
23
|
+
* Make your feature addition or bug fix.
|
24
|
+
* Add tests for it. This is important so I don't break it in a
|
25
|
+
future version unintentionally.
|
26
|
+
* Commit, do not mess with rakefile, version, or history.
|
27
|
+
(if you want to have your own version, that is fine but
|
28
|
+
bump version in a commit by itself I can ignore when I pull)
|
29
|
+
* Send me a pull request. Bonus points for topic branches.
|
30
|
+
|
31
|
+
== Copyright
|
32
|
+
|
33
|
+
Copyright (c) 2009 Brian Cardarella. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "coder"
|
8
|
+
gem.summary = %Q{Coder}
|
9
|
+
gem.description = %Q{Coder}
|
10
|
+
gem.email = "bcardarella@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/bcardarella/coder"
|
12
|
+
gem.authors = ["Brian Cardarella"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
if File.exist?('VERSION')
|
47
|
+
version = File.read('VERSION')
|
48
|
+
else
|
49
|
+
version = ""
|
50
|
+
end
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "coder #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/coder.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{coder}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Brian Cardarella"]
|
12
|
+
s.date = %q{2009-08-31}
|
13
|
+
s.description = %q{Coder}
|
14
|
+
s.email = %q{bcardarella@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"coder.gemspec",
|
27
|
+
"lib/coder.rb",
|
28
|
+
"lib/countries/countries.rb",
|
29
|
+
"lib/countries/country.rb",
|
30
|
+
"lib/i18n/countries/eng.yml",
|
31
|
+
"lib/i18n/states/us/eng.yml",
|
32
|
+
"lib/states/state.rb",
|
33
|
+
"test/coder_test.rb",
|
34
|
+
"test/countries/countries_test.rb",
|
35
|
+
"test/countries/country_test.rb",
|
36
|
+
"test/states/state_test.rb",
|
37
|
+
"test/test_helper.rb"
|
38
|
+
]
|
39
|
+
s.has_rdoc = true
|
40
|
+
s.homepage = %q{http://github.com/bcardarella/coder}
|
41
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = %q{1.3.2}
|
44
|
+
s.summary = %q{Coder}
|
45
|
+
s.test_files = [
|
46
|
+
"test/coder_test.rb",
|
47
|
+
"test/countries/countries_test.rb",
|
48
|
+
"test/countries/country_test.rb",
|
49
|
+
"test/states/state_test.rb",
|
50
|
+
"test/test_helper.rb"
|
51
|
+
]
|
52
|
+
|
53
|
+
if s.respond_to? :specification_version then
|
54
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
55
|
+
s.specification_version = 3
|
56
|
+
|
57
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
58
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
64
|
+
end
|
65
|
+
end
|
data/lib/coder.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Coder
|
2
|
+
class Countries
|
3
|
+
attr_accessor :loaded_countries
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.load_yaml
|
7
|
+
end
|
8
|
+
|
9
|
+
def load_yaml
|
10
|
+
self.loaded_countries = YAML.load_file(yaml_file_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def yaml_file_name
|
14
|
+
"#{File.dirname(__FILE__)}/../i18n/countries/#{Coder.i18n}.yml"
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](_code)
|
18
|
+
_code = _code.to_s.upcase.to_sym
|
19
|
+
country = loaded_countries[_code]
|
20
|
+
Coder::Country.new(:code => _code.to_s, :name => country)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.[](_code)
|
24
|
+
countries = self.new
|
25
|
+
countries[_code]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Coder
|
2
|
+
class Country
|
3
|
+
attr_accessor :loaded_states, :code, :name
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
self.code = args[:code].to_s
|
7
|
+
self.name = args[:name]
|
8
|
+
|
9
|
+
self.load_yaml
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_yaml
|
13
|
+
self.loaded_states = YAML.load_file(yaml_file_name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def yaml_file_name
|
17
|
+
"#{File.dirname(__FILE__)}/../i18n/states/#{code.downcase}/#{Coder.i18n}.yml"
|
18
|
+
end
|
19
|
+
|
20
|
+
def [](_code)
|
21
|
+
_code = _code.to_s.upcase.to_sym
|
22
|
+
state = loaded_states[_code]
|
23
|
+
Coder::State.new(:code => _code.to_s, :name => state)
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,252 @@
|
|
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
|
data/lib/states/state.rb
ADDED
data/test/coder_test.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CoderTest < Test::Unit::TestCase
|
4
|
+
context "i18n" do
|
5
|
+
should "default to :eng" do
|
6
|
+
assert_equal :eng, Coder.i18n
|
7
|
+
end
|
8
|
+
|
9
|
+
should "set the Internationalization code to :gla (Gaelic)" do
|
10
|
+
Coder.i18n = :gla
|
11
|
+
assert_equal :gla, Coder.i18n
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CountriesTest < Test::Unit::TestCase
|
4
|
+
context "English" do
|
5
|
+
setup do
|
6
|
+
Coder.i18n = :eng
|
7
|
+
end
|
8
|
+
|
9
|
+
context "Loading the YAML" do
|
10
|
+
setup do
|
11
|
+
@countries = Coder::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 #loaded_countries with the country data" do
|
19
|
+
YAML.expects(:load_file).returns({:US => "United States"})
|
20
|
+
@countries.load_yaml
|
21
|
+
assert "United States", @countries.loaded_countries[:US]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "a new object" do
|
26
|
+
should "load the yaml" do
|
27
|
+
Coder::Countries.any_instance.expects(:load_yaml)
|
28
|
+
Coder::Countries.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "Getting a country" do
|
33
|
+
setup do
|
34
|
+
@countries = Coder::Countries.new
|
35
|
+
end
|
36
|
+
|
37
|
+
should "return a country object of \"United States\" for :US" do
|
38
|
+
country = @countries[:US]
|
39
|
+
assert_equal Coder::Country, country.class
|
40
|
+
assert_equal "United States", country.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
should "return a country object of \"United States\" for :us" do
|
44
|
+
country = @countries[:us]
|
45
|
+
assert_equal Coder::Country, country.class
|
46
|
+
assert_equal "United States", country.to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
should "return a country object of \"United States\" for \"US\"" do
|
50
|
+
country = @countries["US"]
|
51
|
+
assert_equal Coder::Country, country.class
|
52
|
+
assert_equal "United States", country.to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
should "return a country object of \"United States\" for \"us\"" do
|
56
|
+
country = @countries["us"]
|
57
|
+
assert_equal Coder::Country, country.class
|
58
|
+
assert_equal "United States", country.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
context "Getting a country alternate form" do
|
64
|
+
|
65
|
+
should "return a country object of \"United States\" for :US" do
|
66
|
+
country = Coder::Countries[:US]
|
67
|
+
assert_equal Coder::Country, country.class
|
68
|
+
assert_equal "United States", country.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
should "return a country object of \"United States\" for :us" do
|
72
|
+
country = Coder::Countries[:us]
|
73
|
+
assert_equal Coder::Country, country.class
|
74
|
+
assert_equal "United States", country.to_s
|
75
|
+
end
|
76
|
+
|
77
|
+
should "return a country object of \"United States\" for \"US\"" do
|
78
|
+
country = Coder::Countries["US"]
|
79
|
+
assert_equal Coder::Country, country.class
|
80
|
+
assert_equal "United States", country.to_s
|
81
|
+
end
|
82
|
+
|
83
|
+
should "return a country object of \"United States\" for \"us\"" do
|
84
|
+
country = Coder::Countries["us"]
|
85
|
+
assert_equal Coder::Country, country.class
|
86
|
+
assert_equal "United States", country.to_s
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CountryTest < Test::Unit::TestCase
|
4
|
+
context "English" do
|
5
|
+
setup do
|
6
|
+
Coder.i18n = :eng
|
7
|
+
end
|
8
|
+
|
9
|
+
context "Loading the YAML" do
|
10
|
+
setup do
|
11
|
+
@country = Coder::Country.new(:code => "US", :name => "United States")
|
12
|
+
end
|
13
|
+
|
14
|
+
should "load yaml/states/us/eng.yml" do
|
15
|
+
assert_match /eng.yml/, @country.yaml_file_name
|
16
|
+
assert_match /us/, @country.yaml_file_name
|
17
|
+
end
|
18
|
+
|
19
|
+
should "set the #loaded_states with the US state data" do
|
20
|
+
YAML.expects(:load_file).returns({:MA => "Massachusetts"})
|
21
|
+
@country.load_yaml
|
22
|
+
assert "Massachusetts", @country.loaded_states[:MA]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "a new object" do
|
27
|
+
should "load the yaml" do
|
28
|
+
Coder::Country.any_instance.expects(:load_yaml)
|
29
|
+
Coder::Country.new(:code => "US", :name => "United States")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "Getting a state" do
|
34
|
+
setup do
|
35
|
+
@country = Coder::Country.new(:code => "US", :name => "United States")
|
36
|
+
end
|
37
|
+
|
38
|
+
should "return a state object of \"Massachusetts\" for :MA" do
|
39
|
+
state = @country[:MA]
|
40
|
+
assert_equal Coder::State, state.class
|
41
|
+
assert_equal "Massachusetts", state.to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
should "return a state object of \"Massachusetts\" for :ma" do
|
45
|
+
state = @country[:ma]
|
46
|
+
assert_equal Coder::State, state.class
|
47
|
+
assert_equal "Massachusetts", state.to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
should "return a state object of \"Massachusetts\" for \"MA\"" do
|
51
|
+
state = @country["MA"]
|
52
|
+
assert_equal Coder::State, state.class
|
53
|
+
assert_equal "Massachusetts", state.to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
should "return a state object of \"Massachusetts\" for \"ma\"" do
|
57
|
+
state = @country["ma"]
|
58
|
+
assert_equal Coder::State, state.class
|
59
|
+
assert_equal "Massachusetts", state.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
should "return 'United States' for #to_s" do
|
65
|
+
country = Coder::Country.new(:code => "US", :name => "United States")
|
66
|
+
assert_equal "United States", country.to_s
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class StateTest < Test::Unit::TestCase
|
4
|
+
context "English" do
|
5
|
+
setup do
|
6
|
+
Coder.i18n = :eng
|
7
|
+
end
|
8
|
+
|
9
|
+
context "Getters" do
|
10
|
+
setup do
|
11
|
+
@state = Coder::State.new(:code => "MA", :name => "Massachusetts")
|
12
|
+
end
|
13
|
+
|
14
|
+
should "return 'Massachusetts' for #to_s" do
|
15
|
+
assert_equal "Massachusetts", @state.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
should "return 'Massachusetts' for #name" do
|
19
|
+
assert_equal "Massachusetts", @state.name
|
20
|
+
end
|
21
|
+
|
22
|
+
should "return \"MA\" for #code" do
|
23
|
+
assert_equal "MA", @state.code
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'ruby-debug'
|
5
|
+
require 'mocha'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
require 'coder'
|
10
|
+
|
11
|
+
class Test::Unit::TestCase
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bcardarella-coder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Cardarella
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-31 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Coder
|
26
|
+
email: bcardarella@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- coder.gemspec
|
42
|
+
- lib/coder.rb
|
43
|
+
- lib/countries/countries.rb
|
44
|
+
- lib/countries/country.rb
|
45
|
+
- lib/i18n/countries/eng.yml
|
46
|
+
- lib/i18n/states/us/eng.yml
|
47
|
+
- lib/states/state.rb
|
48
|
+
- test/coder_test.rb
|
49
|
+
- test/countries/countries_test.rb
|
50
|
+
- test/countries/country_test.rb
|
51
|
+
- test/states/state_test.rb
|
52
|
+
- test/test_helper.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/bcardarella/coder
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options:
|
57
|
+
- --charset=UTF-8
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.2.0
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Coder
|
79
|
+
test_files:
|
80
|
+
- test/coder_test.rb
|
81
|
+
- test/countries/countries_test.rb
|
82
|
+
- test/countries/country_test.rb
|
83
|
+
- test/states/state_test.rb
|
84
|
+
- test/test_helper.rb
|