decoder 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/decoder.gemspec +14 -59
- data/lib/decoder.rb +2 -3
- data/lib/decoder/common_methods.rb +11 -0
- data/lib/decoder/countries.rb +1 -1
- data/lib/decoder/country.rb +5 -3
- data/lib/{locales → decoder/locales}/en.yml +3 -1
- data/lib/decoder/state.rb +4 -2
- data/lib/decoder/version.rb +3 -0
- metadata +26 -45
- data/.document +0 -5
- data/.gitignore +0 -5
- data/LICENSE +0 -20
- data/README.rdoc +0 -47
- data/Rakefile +0 -56
- data/VERSION +0 -1
- data/lib/common_methods.rb +0 -9
- data/test/common_methods_test.rb +0 -24
- data/test/countries/countries_test.rb +0 -82
- data/test/countries/country_test.rb +0 -102
- data/test/decoder_test.rb +0 -30
- data/test/states/state_test.rb +0 -44
- data/test/test_helper.rb +0 -12
data/decoder.gemspec
CHANGED
@@ -1,66 +1,21 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "decoder/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
9
|
-
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
6
|
+
s.name = "decoder"
|
7
|
+
s.version = Decoder::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Brian Cardarella"]
|
10
|
+
s.email = ["bcardarella@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/bcardarella/decoder"
|
12
|
+
s.summary = %q{Decoder}
|
13
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/decoder.rb",
|
29
|
-
"lib/decoder/countries.rb",
|
30
|
-
"lib/decoder/country.rb",
|
31
|
-
"lib/decoder/state.rb",
|
32
|
-
"lib/locales/en.yml",
|
33
|
-
"test/common_methods_test.rb",
|
34
|
-
"test/countries/countries_test.rb",
|
35
|
-
"test/countries/country_test.rb",
|
36
|
-
"test/decoder_test.rb",
|
37
|
-
"test/states/state_test.rb",
|
38
|
-
"test/test_helper.rb"
|
39
|
-
]
|
40
|
-
s.homepage = %q{http://github.com/bcardarella/decoder}
|
41
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
42
|
-
s.require_paths = ["lib"]
|
43
|
-
s.rubygems_version = %q{1.3.5}
|
44
|
-
s.summary = %q{Decoder}
|
45
|
-
s.test_files = [
|
46
|
-
"test/common_methods_test.rb",
|
47
|
-
"test/countries/countries_test.rb",
|
48
|
-
"test/countries/country_test.rb",
|
49
|
-
"test/decoder_test.rb",
|
50
|
-
"test/states/state_test.rb",
|
51
|
-
"test/test_helper.rb"
|
52
|
-
]
|
53
14
|
|
54
|
-
|
55
|
-
|
56
|
-
|
15
|
+
s.files = `git ls-files -- {lib/*,*.gemspec}`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
17
|
+
s.require_paths = ["lib"]
|
57
18
|
|
58
|
-
|
59
|
-
|
60
|
-
else
|
61
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
62
|
-
end
|
63
|
-
else
|
64
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
65
|
-
end
|
19
|
+
s.add_development_dependency 'shoulda-context'
|
20
|
+
s.add_development_dependency 'bourne'
|
66
21
|
end
|
data/lib/decoder.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
require 'common_methods'
|
3
2
|
require 'decoder/countries'
|
4
3
|
require 'decoder/country'
|
5
4
|
require 'decoder/state'
|
@@ -28,7 +27,7 @@ module Decoder
|
|
28
27
|
end
|
29
28
|
|
30
29
|
def self.yaml_file_name
|
31
|
-
"#{File.dirname(__FILE__)}/locales/#{Decoder.i18n}.yml"
|
30
|
+
"#{File.dirname(__FILE__)}/decoder/locales/#{Decoder.i18n}.yml"
|
32
31
|
end
|
33
32
|
|
34
|
-
end
|
33
|
+
end
|
data/lib/decoder/countries.rb
CHANGED
data/lib/decoder/country.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require 'decoder/common_methods'
|
2
|
+
|
1
3
|
module Decoder
|
2
4
|
class Country
|
3
|
-
include
|
5
|
+
include CommonMethods
|
4
6
|
attr_accessor :code, :name
|
5
7
|
|
6
8
|
def initialize(args)
|
@@ -30,11 +32,11 @@ module Decoder
|
|
30
32
|
end
|
31
33
|
Decoder::State.new(:code => _code, :name => state, :fips => fips)
|
32
34
|
end
|
33
|
-
|
35
|
+
|
34
36
|
def by_fips(fips)
|
35
37
|
fips = fips.to_s
|
36
38
|
state = states.detect { |k,v| v.include?(fips) if v.is_a?(Array) }
|
37
39
|
self[state.first]
|
38
40
|
end
|
39
41
|
end
|
40
|
-
end
|
42
|
+
end
|
data/lib/decoder/state.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require 'decoder/common_methods'
|
2
|
+
|
1
3
|
module Decoder
|
2
4
|
class State
|
3
|
-
include
|
5
|
+
include CommonMethods
|
4
6
|
attr_accessor :code, :name, :fips
|
5
7
|
|
6
8
|
def initialize(args)
|
@@ -9,4 +11,4 @@ module Decoder
|
|
9
11
|
self.fips = args[:fips].to_i if args[:fips]
|
10
12
|
end
|
11
13
|
end
|
12
|
-
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 8
|
9
|
-
- 1
|
10
|
-
version: 0.8.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.9.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Brian Cardarella
|
@@ -15,54 +10,51 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
13
|
+
date: 2011-10-26 00:00:00 -04:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
22
|
-
name: shoulda
|
17
|
+
name: shoulda-context
|
23
18
|
prerelease: false
|
24
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
20
|
none: false
|
26
21
|
requirements:
|
27
22
|
- - ">="
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
|
-
segments:
|
31
|
-
- 0
|
32
24
|
version: "0"
|
33
25
|
type: :development
|
34
26
|
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bourne
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
35
38
|
description: Decoder
|
36
|
-
email:
|
39
|
+
email:
|
40
|
+
- bcardarella@gmail.com
|
37
41
|
executables: []
|
38
42
|
|
39
43
|
extensions: []
|
40
44
|
|
41
|
-
extra_rdoc_files:
|
42
|
-
|
43
|
-
- README.rdoc
|
45
|
+
extra_rdoc_files: []
|
46
|
+
|
44
47
|
files:
|
45
|
-
- .document
|
46
|
-
- .gitignore
|
47
|
-
- LICENSE
|
48
|
-
- README.rdoc
|
49
|
-
- Rakefile
|
50
|
-
- VERSION
|
51
48
|
- decoder.gemspec
|
52
|
-
- lib/common_methods.rb
|
53
49
|
- lib/decoder.rb
|
50
|
+
- lib/decoder/common_methods.rb
|
54
51
|
- lib/decoder/countries.rb
|
55
52
|
- lib/decoder/country.rb
|
53
|
+
- lib/decoder/locales/en.yml
|
56
54
|
- lib/decoder/state.rb
|
57
|
-
- lib/
|
58
|
-
- test/common_methods_test.rb
|
59
|
-
- test/countries/countries_test.rb
|
60
|
-
- test/countries/country_test.rb
|
61
|
-
- test/decoder_test.rb
|
62
|
-
- test/states/state_test.rb
|
63
|
-
- test/test_helper.rb
|
55
|
+
- lib/decoder/version.rb
|
64
56
|
has_rdoc: true
|
65
|
-
homepage:
|
57
|
+
homepage: https://github.com/bcardarella/decoder
|
66
58
|
licenses: []
|
67
59
|
|
68
60
|
post_install_message:
|
@@ -75,30 +67,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
67
|
requirements:
|
76
68
|
- - ">="
|
77
69
|
- !ruby/object:Gem::Version
|
78
|
-
hash: 3
|
79
|
-
segments:
|
80
|
-
- 0
|
81
70
|
version: "0"
|
82
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
72
|
none: false
|
84
73
|
requirements:
|
85
74
|
- - ">="
|
86
75
|
- !ruby/object:Gem::Version
|
87
|
-
hash: 3
|
88
|
-
segments:
|
89
|
-
- 0
|
90
76
|
version: "0"
|
91
77
|
requirements: []
|
92
78
|
|
93
79
|
rubyforge_project:
|
94
|
-
rubygems_version: 1.3.
|
80
|
+
rubygems_version: 1.3.9.3
|
95
81
|
signing_key:
|
96
82
|
specification_version: 3
|
97
83
|
summary: Decoder
|
98
|
-
test_files:
|
99
|
-
|
100
|
-
- test/countries/countries_test.rb
|
101
|
-
- test/countries/country_test.rb
|
102
|
-
- test/decoder_test.rb
|
103
|
-
- test/states/state_test.rb
|
104
|
-
- test/test_helper.rb
|
84
|
+
test_files: []
|
85
|
+
|
data/.document
DELETED
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
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
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
=decoder
|
2
|
-
|
3
|
-
= Usage
|
4
|
-
|
5
|
-
>> Decoder.i18n = :en
|
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
|
-
= FIPS
|
16
|
-
http://en.wikipedia.org/wiki/Federal_Information_Processing_Standard
|
17
|
-
Certain US States have FIPS codes. You can either get the code for a state
|
18
|
-
or look up a state by its FIPS code:
|
19
|
-
|
20
|
-
>> Decoder.i18n = :en
|
21
|
-
>> country = Decoder::Countries[:US]
|
22
|
-
>> state = country[:MA]
|
23
|
-
>> state.fips
|
24
|
-
=> 25
|
25
|
-
>> state = country.by_fips(25)
|
26
|
-
>> state.to_s
|
27
|
-
=> "Massachusetts"
|
28
|
-
|
29
|
-
= i18n
|
30
|
-
When adding a new language please use the ISO 639-1 Code 2-letter standard.
|
31
|
-
You can find the appropriate code for a given language here:
|
32
|
-
http://www.loc.gov/standards/iso639-2/php/code_list.php
|
33
|
-
|
34
|
-
== Note on Patches/Pull Requests
|
35
|
-
|
36
|
-
* Fork the project.
|
37
|
-
* Make your feature addition or bug fix.
|
38
|
-
* Add tests for it. This is important so I don't break it in a
|
39
|
-
future version unintentionally.
|
40
|
-
* Commit, do not mess with rakefile, version, or history.
|
41
|
-
(if you want to have your own version, that is fine but
|
42
|
-
bump version in a commit by itself I can ignore when I pull)
|
43
|
-
* Send me a pull request. Bonus points for topic branches.
|
44
|
-
|
45
|
-
== Copyright
|
46
|
-
|
47
|
-
Copyright (c) 2009 Brian Cardarella. See LICENSE for details.
|
data/Rakefile
DELETED
@@ -1,56 +0,0 @@
|
|
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/bcardarella/decoder"
|
12
|
-
gem.authors = ["Brian Cardarella"]
|
13
|
-
gem.add_development_dependency "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
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.8.1
|
data/lib/common_methods.rb
DELETED
data/test/common_methods_test.rb
DELETED
@@ -1,24 +0,0 @@
|
|
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
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CountriesTest < Test::Unit::TestCase
|
4
|
-
should "print '#<#class>" do
|
5
|
-
assert_equal "#<Decoder::Countries>", Decoder::Countries.new.inspect
|
6
|
-
end
|
7
|
-
|
8
|
-
context "English" do
|
9
|
-
setup do
|
10
|
-
Decoder.i18n = :en
|
11
|
-
end
|
12
|
-
|
13
|
-
context "A new object" do
|
14
|
-
should "load the yaml" do
|
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
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "Getting a country" do
|
22
|
-
setup do
|
23
|
-
@countries = Decoder::Countries.new
|
24
|
-
end
|
25
|
-
|
26
|
-
should "return a country object of \"United States\" for :US" do
|
27
|
-
country = @countries[:US]
|
28
|
-
assert_equal Decoder::Country, country.class
|
29
|
-
assert_equal "United States", country.to_s
|
30
|
-
end
|
31
|
-
|
32
|
-
should "return a country object of \"United States\" for :us" do
|
33
|
-
country = @countries[:us]
|
34
|
-
assert_equal Decoder::Country, country.class
|
35
|
-
assert_equal "United States", country.to_s
|
36
|
-
end
|
37
|
-
|
38
|
-
should "return a country object of \"United States\" for \"US\"" do
|
39
|
-
country = @countries["US"]
|
40
|
-
assert_equal Decoder::Country, country.class
|
41
|
-
assert_equal "United States", country.to_s
|
42
|
-
end
|
43
|
-
|
44
|
-
should "return a country object of \"United States\" for \"us\"" do
|
45
|
-
country = @countries["us"]
|
46
|
-
assert_equal Decoder::Country, country.class
|
47
|
-
assert_equal "United States", country.to_s
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
context "Getting a country alternate form" do
|
53
|
-
|
54
|
-
should "return a country object of \"United States\" for :US" do
|
55
|
-
country = Decoder::Countries[:US]
|
56
|
-
assert_equal Decoder::Country, country.class
|
57
|
-
assert_equal "United States", country.to_s
|
58
|
-
end
|
59
|
-
|
60
|
-
should "return a country object of \"United States\" for :us" do
|
61
|
-
country = Decoder::Countries[:us]
|
62
|
-
assert_equal Decoder::Country, country.class
|
63
|
-
assert_equal "United States", country.to_s
|
64
|
-
end
|
65
|
-
|
66
|
-
should "return a country object of \"United States\" for \"US\"" do
|
67
|
-
country = Decoder::Countries["US"]
|
68
|
-
assert_equal Decoder::Country, country.class
|
69
|
-
assert_equal "United States", country.to_s
|
70
|
-
end
|
71
|
-
|
72
|
-
should "return a country object of \"United States\" for \"us\"" do
|
73
|
-
country = Decoder::Countries["us"]
|
74
|
-
assert_equal Decoder::Country, country.class
|
75
|
-
assert_equal "United States", country.to_s
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CountryTest < Test::Unit::TestCase
|
4
|
-
should "include 'Common Methods' module" do
|
5
|
-
assert_contains Decoder::State.included_modules, CommonMethods
|
6
|
-
end
|
7
|
-
|
8
|
-
context "English for US" do
|
9
|
-
setup do
|
10
|
-
Decoder.i18n = :en
|
11
|
-
end
|
12
|
-
|
13
|
-
context "A new country" do
|
14
|
-
should "load the yaml" do
|
15
|
-
Decoder.expects(:load_yaml).returns({:en => {"US" => {:name => "United States", :states => {"MA" => "Massachusetts"}}}})
|
16
|
-
|
17
|
-
country = Decoder::Country.new(:code => "US", :name => "United States")
|
18
|
-
assert_not_nil country.states
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "Getting a state" do
|
23
|
-
setup do
|
24
|
-
@country = Decoder::Country.new(:code => "US", :name => "United States")
|
25
|
-
end
|
26
|
-
|
27
|
-
context "by code" do
|
28
|
-
should "return a state object of \"Massachusetts\" for :MA" do
|
29
|
-
state = @country[:MA]
|
30
|
-
assert_equal Decoder::State, state.class
|
31
|
-
assert_equal "Massachusetts", state.name
|
32
|
-
end
|
33
|
-
|
34
|
-
should "return a state object of \"Massachusetts\" for :ma" do
|
35
|
-
state = @country[:ma]
|
36
|
-
assert_equal Decoder::State, state.class
|
37
|
-
assert_equal "Massachusetts", state.name
|
38
|
-
end
|
39
|
-
|
40
|
-
should "return a state object of \"Massachusetts\" for \"MA\"" do
|
41
|
-
state = @country["MA"]
|
42
|
-
assert_equal Decoder::State, state.class
|
43
|
-
assert_equal "Massachusetts", state.name
|
44
|
-
end
|
45
|
-
|
46
|
-
should "return a state object of \"Massachusetts\" for \"ma\"" do
|
47
|
-
state = @country["ma"]
|
48
|
-
assert_equal Decoder::State, state.class
|
49
|
-
assert_equal "Massachusetts", state.name
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context "by FIPS" do
|
54
|
-
should "return a state object of \"Massachusetts\" for 25" do
|
55
|
-
state = @country.by_fips(25)
|
56
|
-
assert_equal Decoder::State, state.class
|
57
|
-
assert_equal "Massachusetts", state.name
|
58
|
-
end
|
59
|
-
|
60
|
-
should "return a state object of \"Massachusetts\" for \"25\"" do
|
61
|
-
state = @country.by_fips("25")
|
62
|
-
assert_equal Decoder::State, state.class
|
63
|
-
assert_equal "Massachusetts", state.name
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "#states" do
|
69
|
-
setup do
|
70
|
-
@country = Decoder::Country.new(:code => "US", :name => "United States")
|
71
|
-
end
|
72
|
-
|
73
|
-
context "For a FIPS state" do
|
74
|
-
should "be a hash of states" do
|
75
|
-
assert_equal ["Massachusetts", "25"], @country.states["MA"]
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context "For a non-FIPS state" do
|
80
|
-
should "be a hash of states" do
|
81
|
-
assert_equal "Northern Mariana Islands", @country.states["MP"]
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "aliases" do
|
86
|
-
should "be equal for #states and #counties" do
|
87
|
-
assert_equal @country.states, @country.counties
|
88
|
-
end
|
89
|
-
|
90
|
-
should "be equal for #states and #provinces" do
|
91
|
-
assert_equal @country.states, @country.provinces
|
92
|
-
end
|
93
|
-
|
94
|
-
should "be equal for #states and #territories" do
|
95
|
-
assert_equal @country.states, @country.territories
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
data/test/decoder_test.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class DecoderTest < Test::Unit::TestCase
|
4
|
-
context "i18n" do
|
5
|
-
should "default to :eng" do
|
6
|
-
assert_equal :en, Decoder.i18n
|
7
|
-
end
|
8
|
-
|
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")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/test/states/state_test.rb
DELETED
@@ -1,44 +0,0 @@
|
|
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 = :en
|
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
|
-
|
28
|
-
context "FIPS states from a country" do
|
29
|
-
setup do
|
30
|
-
@country = Decoder::Countries["US"]
|
31
|
-
@state = @country["MA"]
|
32
|
-
end
|
33
|
-
|
34
|
-
should "properly assign the name" do
|
35
|
-
assert_equal "Massachusetts", @state.name
|
36
|
-
end
|
37
|
-
|
38
|
-
should "properly assign the fips" do
|
39
|
-
assert_equal 25, @state.fips
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,12 +0,0 @@
|
|
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
|