decoder 0.5.1

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 ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
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
+ =decoder
2
+
3
+ = Usage
4
+
5
+ >> Decoder.i18n = :eng
6
+ >> country = Decoder::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 = "decoder"
8
+ gem.summary = %Q{Decoder}
9
+ gem.description = %Q{Decoder}
10
+ gem.email = "bcardarella@gmail.com"
11
+ gem.homepage = "http://github.com/bcardarelladecoder"
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 = "decoder #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.1
data/decoder.gemspec ADDED
@@ -0,0 +1,70 @@
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{decoder}
8
+ s.version = "0.5.1"
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-09-01}
13
+ s.description = %q{Decoder}
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
+ "decoder.gemspec",
27
+ "lib/common_methods.rb",
28
+ "lib/countries/countries.rb",
29
+ "lib/countries/country.rb",
30
+ "lib/decoder.rb",
31
+ "lib/i18n/countries/eng.yml",
32
+ "lib/i18n/states/au/eng.yml",
33
+ "lib/i18n/states/ca/eng.yml",
34
+ "lib/i18n/states/us/eng.yml",
35
+ "lib/states/state.rb",
36
+ "test/common_methods_test.rb",
37
+ "test/countries/countries_test.rb",
38
+ "test/countries/country_test.rb",
39
+ "test/decoder_test.rb",
40
+ "test/states/state_test.rb",
41
+ "test/test_helper.rb"
42
+ ]
43
+ s.has_rdoc = true
44
+ s.homepage = %q{http://github.com/bcardarelladecoder}
45
+ s.rdoc_options = ["--charset=UTF-8"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = %q{1.3.2}
48
+ s.summary = %q{Decoder}
49
+ s.test_files = [
50
+ "test/common_methods_test.rb",
51
+ "test/countries/countries_test.rb",
52
+ "test/countries/country_test.rb",
53
+ "test/decoder_test.rb",
54
+ "test/states/state_test.rb",
55
+ "test/test_helper.rb"
56
+ ]
57
+
58
+ if s.respond_to? :specification_version then
59
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
60
+ s.specification_version = 3
61
+
62
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
63
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
64
+ else
65
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
69
+ end
70
+ end
@@ -0,0 +1,9 @@
1
+ module CommonMethods
2
+ def to_s
3
+ name
4
+ end
5
+
6
+ def inspect
7
+ %{#<#{self.class} code: #{code}, name: #{name}>}
8
+ end
9
+ end
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,29 @@
1
+ module Decoder
2
+ class Country
3
+ include ::CommonMethods
4
+ attr_accessor :states, :code, :name
5
+ alias_method :provinces, :states
6
+ alias_method :territories, :states
7
+
8
+ def initialize(args)
9
+ self.code = args[:code].to_s
10
+ self.name = args[:name]
11
+
12
+ self.load_yaml
13
+ end
14
+
15
+ def load_yaml
16
+ self.states = YAML.load_file(yaml_file_name)
17
+ end
18
+
19
+ def yaml_file_name
20
+ "#{File.dirname(__FILE__)}/../i18n/states/#{code.downcase}/#{Decoder.i18n}.yml"
21
+ end
22
+
23
+ def [](_code)
24
+ _code = _code.to_s.upcase
25
+ state = states[_code]
26
+ Decoder::State.new(:code => _code, :name => state)
27
+ end
28
+ end
29
+ end
data/lib/decoder.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'common_methods'
2
+ require 'countries/countries'
3
+ require 'countries/country'
4
+ require 'states/state'
5
+
6
+ module Decoder
7
+ def self.i18n
8
+ @i18n ||= :eng
9
+ end
10
+
11
+ def self.i18n=(code)
12
+ @i18n = code
13
+ end
14
+ 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
@@ -0,0 +1,9 @@
1
+ ---
2
+ ACT: Australian Capital Territory
3
+ NSW: New South Wales
4
+ N T: Northern Territory
5
+ QLD: Queensland
6
+ SA: South Australia
7
+ TAS: Tasmania
8
+ VIC: Victoria
9
+ W A: Western Australia
@@ -0,0 +1,14 @@
1
+ ---
2
+ ON: Ontario
3
+ NB: New Brunswick
4
+ PE: Prince Edward Island
5
+ NL: Newfoundland and Labrador
6
+ QC: Quebec
7
+ NT: Northwest Territories
8
+ SK: Saskatchewan
9
+ AB: Alberta
10
+ NS: Nova Scotia
11
+ YT: Yukon
12
+ BC: British Columbia
13
+ NU: Nunavut
14
+ MB: Manitoba
@@ -0,0 +1,60 @@
1
+ ---
2
+ HI: Hawaii
3
+ KY: Kentucky
4
+ MN: Minnesota
5
+ OK: Oklahoma
6
+ FM: Federated States Of Micronesia
7
+ MT: Montana
8
+ NJ: New Jersey
9
+ PW: Palau
10
+ SD: South Dakota
11
+ VI: Virgin Islands
12
+ WA: Washington
13
+ DE: Delaware
14
+ IA: Iowa
15
+ MO: Missouri
16
+ OR: Oregon
17
+ AK: Alaska
18
+ MH: Marshall Islands
19
+ NM: New Mexico
20
+ WV: West Virginia
21
+ ID: Idaho
22
+ IL: Illinois
23
+ KS: Kansas
24
+ LA: Louisiana
25
+ MA: Massachusetts
26
+ MP: Northern Mariana Islands
27
+ RI: Rhode Island
28
+ VA: Virginia
29
+ CT: Connecticut
30
+ NY: New York
31
+ WI: Wisconsin
32
+ GU: Guam
33
+ MI: Michigan
34
+ NC: North Carolina
35
+ PR: Puerto Rico
36
+ TX: Texas
37
+ DC: District Of Columbia
38
+ ND: North Dakota
39
+ TN: T:Tnessee
40
+ WY: Wyoming
41
+ AR: Arkansas
42
+ IN: Indiana
43
+ MD: Maryland
44
+ NE: Nebraska
45
+ NV: Nevada
46
+ UT: Utah
47
+ AL: Alabama
48
+ AZ: Arizona
49
+ FL: Florida
50
+ GA: Georgia
51
+ OH: Ohio
52
+ AS: American Samoa
53
+ CA: California
54
+ CO: Colorado
55
+ ME: Maine
56
+ MS: Mississippi
57
+ NH: New Hampshire
58
+ PA: Pennsylvania
59
+ SC: South Carolina
60
+ VT: Vermont
@@ -0,0 +1,11 @@
1
+ module Decoder
2
+ class State
3
+ include ::CommonMethods
4
+ attr_accessor :code, :name
5
+
6
+ def initialize(args)
7
+ self.code = args[:code].to_s
8
+ self.name = args[:name]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ class CommonMethodsTest < Test::Unit::TestCase
4
+
5
+ class EmptyClass
6
+ include CommonMethods
7
+ attr_accessor :code, :name
8
+ end
9
+
10
+ context "CommonMethods" do
11
+ setup do
12
+ @empty_class = EmptyClass.new
13
+ @empty_class.code = "TS"
14
+ @empty_class.name = "TEST"
15
+ end
16
+ should "print #name for #to_s" do
17
+ assert_equal @empty_class.name, @empty_class.to_s
18
+ end
19
+
20
+ should "print '#<#class code: code, #name: #name>" do
21
+ assert_equal "#<CommonMethodsTest::EmptyClass code: TS, name: TEST>", @empty_class.inspect
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,93 @@
1
+ require 'test_helper'
2
+
3
+ class CountriesTest < Test::Unit::TestCase
4
+ context "English" do
5
+ 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
23
+ end
24
+
25
+ context "a new object" do
26
+ should "load the yaml" do
27
+ Decoder::Countries.any_instance.expects(:load_yaml)
28
+ Decoder::Countries.new
29
+ end
30
+ end
31
+
32
+ context "Getting a country" do
33
+ setup do
34
+ @countries = Decoder::Countries.new
35
+ end
36
+
37
+ should "return a country object of \"United States\" for :US" do
38
+ country = @countries[:US]
39
+ assert_equal Decoder::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 Decoder::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 Decoder::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 Decoder::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 = Decoder::Countries[:US]
67
+ assert_equal Decoder::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 = Decoder::Countries[:us]
73
+ assert_equal Decoder::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 = Decoder::Countries["US"]
79
+ assert_equal Decoder::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 = Decoder::Countries["us"]
85
+ assert_equal Decoder::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,81 @@
1
+ require 'test_helper'
2
+
3
+ class CountryTest < Test::Unit::TestCase
4
+
5
+ should "include 'Common Methods' module" do
6
+ assert_contains Decoder::State.included_modules, CommonMethods
7
+ end
8
+
9
+ context "English" do
10
+ setup do
11
+ Decoder.i18n = :eng
12
+ end
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
32
+ should "load the yaml" do
33
+ Decoder::Country.any_instance.expects(:load_yaml)
34
+ Decoder::Country.new(:code => "US", :name => "United States")
35
+ end
36
+ end
37
+
38
+ context "Getting a state" do
39
+ setup do
40
+ @country = Decoder::Country.new(:code => "US", :name => "United States")
41
+ end
42
+
43
+ should "return a state object of \"Massachusetts\" for :MA" do
44
+ state = @country[:MA]
45
+ assert_equal Decoder::State, state.class
46
+ end
47
+
48
+ should "return a state object of \"Massachusetts\" for :ma" do
49
+ state = @country[:ma]
50
+ assert_equal Decoder::State, state.class
51
+ end
52
+
53
+ should "return a state object of \"Massachusetts\" for \"MA\"" do
54
+ state = @country["MA"]
55
+ assert_equal Decoder::State, state.class
56
+ end
57
+
58
+ should "return a state object of \"Massachusetts\" for \"ma\"" do
59
+ state = @country["ma"]
60
+ assert_equal Decoder::State, state.class
61
+ end
62
+
63
+ 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
74
+ end
75
+
76
+ should "be equal for #states and #territories" do
77
+ assert_equal @country.states, @country.territories
78
+ end
79
+ end
80
+
81
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class DecoderTest < Test::Unit::TestCase
4
+ context "i18n" do
5
+ should "default to :eng" do
6
+ assert_equal :eng, Decoder.i18n
7
+ end
8
+
9
+ should "set the Internationalization code to :gla (Gaelic)" do
10
+ Decoder.i18n = :gla
11
+ assert_equal :gla, Decoder.i18n
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class StateTest < Test::Unit::TestCase
4
+
5
+ should "include 'Common Methods' module" do
6
+ assert_contains Decoder::State.included_modules, CommonMethods
7
+ end
8
+
9
+ context "English" do
10
+ setup do
11
+ Decoder.i18n = :eng
12
+ end
13
+
14
+ context "Getters" do
15
+ setup do
16
+ @state = Decoder::State.new(:code => "MA", :name => "Massachusetts")
17
+ end
18
+
19
+ should "return 'Massachusetts' for #name" do
20
+ assert_equal "Massachusetts", @state.name
21
+ end
22
+
23
+ should "return \"MA\" for #code" do
24
+ assert_equal "MA", @state.code
25
+ end
26
+ end
27
+ end
28
+
29
+ end
@@ -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 'decoder'
10
+
11
+ class Test::Unit::TestCase
12
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decoder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
5
+ platform: ruby
6
+ authors:
7
+ - Brian Cardarella
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-01 00:00:00 -04: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: Decoder
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
+ - decoder.gemspec
42
+ - lib/common_methods.rb
43
+ - lib/countries/countries.rb
44
+ - lib/countries/country.rb
45
+ - 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
51
+ - test/common_methods_test.rb
52
+ - test/countries/countries_test.rb
53
+ - test/countries/country_test.rb
54
+ - test/decoder_test.rb
55
+ - test/states/state_test.rb
56
+ - test/test_helper.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/bcardarelladecoder
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.2
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Decoder
85
+ test_files:
86
+ - test/common_methods_test.rb
87
+ - test/countries/countries_test.rb
88
+ - test/countries/country_test.rb
89
+ - test/decoder_test.rb
90
+ - test/states/state_test.rb
91
+ - test/test_helper.rb