decoder 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -0
- data/VERSION +1 -1
- data/decoder.gemspec +7 -8
- data/lib/decoder/country.rb +11 -1
- data/lib/decoder/state.rb +2 -1
- data/lib/locales/en.yml +160 -56
- data/test/countries/countries_test.rb +1 -1
- data/test/countries/country_test.rb +45 -19
- data/test/states/state_test.rb +15 -0
- metadata +7 -7
data/README.rdoc
CHANGED
@@ -12,6 +12,20 @@
|
|
12
12
|
|
13
13
|
Currently the yaml files are still quite incomplete. Please fork and populate!
|
14
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
|
+
|
15
29
|
= i18n
|
16
30
|
When adding a new language please use the ISO 639-1 Code 2-letter standard.
|
17
31
|
You can find the appropriate code for a given language here:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/decoder.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{decoder}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian Cardarella"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2009-11-22}
|
13
13
|
s.description = %q{Decoder}
|
14
14
|
s.email = %q{bcardarella@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
|
|
40
40
|
s.homepage = %q{http://github.com/bcardarella/decoder}
|
41
41
|
s.rdoc_options = ["--charset=UTF-8"]
|
42
42
|
s.require_paths = ["lib"]
|
43
|
-
s.rubygems_version = %q{1.3.
|
43
|
+
s.rubygems_version = %q{1.3.5}
|
44
44
|
s.summary = %q{Decoder}
|
45
45
|
s.test_files = [
|
46
46
|
"test/common_methods_test.rb",
|
@@ -55,13 +55,12 @@ Gem::Specification.new do |s|
|
|
55
55
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
56
56
|
s.specification_version = 3
|
57
57
|
|
58
|
-
if Gem::Version.new(Gem::
|
59
|
-
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
58
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
60
60
|
else
|
61
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
61
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
62
62
|
end
|
63
63
|
else
|
64
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
data/lib/decoder/country.rb
CHANGED
@@ -24,7 +24,17 @@ module Decoder
|
|
24
24
|
def [](_code)
|
25
25
|
_code = _code.to_s.upcase
|
26
26
|
state = states[_code]
|
27
|
-
|
27
|
+
if state.is_a?(Array)
|
28
|
+
fips = state.last
|
29
|
+
state = state.first
|
30
|
+
end
|
31
|
+
Decoder::State.new(:code => _code, :name => state, :fips => fips)
|
32
|
+
end
|
33
|
+
|
34
|
+
def by_fips(fips)
|
35
|
+
fips = fips.to_s
|
36
|
+
state = states.detect { |k,v| v.include?(fips) if v.is_a?(Array) }
|
37
|
+
self[state.first]
|
28
38
|
end
|
29
39
|
end
|
30
40
|
end
|
data/lib/decoder/state.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module Decoder
|
2
2
|
class State
|
3
3
|
include ::CommonMethods
|
4
|
-
attr_accessor :code, :name
|
4
|
+
attr_accessor :code, :name, :fips
|
5
5
|
|
6
6
|
def initialize(args)
|
7
7
|
self.code = args[:code].to_s
|
8
8
|
self.name = args[:name]
|
9
|
+
self.fips = args[:fips].to_i if args[:fips]
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
data/lib/locales/en.yml
CHANGED
@@ -607,66 +607,170 @@
|
|
607
607
|
US:
|
608
608
|
:name: United States
|
609
609
|
:states:
|
610
|
-
VA: Virginia
|
611
|
-
NY: New York
|
612
|
-
ND: North Dakota
|
613
|
-
AL: Alabama
|
614
|
-
HI: Hawaii
|
615
|
-
MN: Minnesota
|
616
|
-
DE: Delaware
|
617
|
-
RI: Rhode Island
|
618
|
-
MD: Maryland
|
619
|
-
NE: Nebraska
|
620
|
-
CO: Colorado
|
621
|
-
IA: Iowa
|
622
|
-
MO: Missouri
|
623
|
-
PR: Puerto Rico
|
624
|
-
WY: Wyoming
|
625
|
-
ME: Maine
|
626
|
-
KY: Kentucky
|
627
|
-
OR: Oregon
|
628
|
-
IL: Illinois
|
629
610
|
MP: Northern Mariana Islands
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
611
|
+
MT:
|
612
|
+
- Montana
|
613
|
+
- "30"
|
614
|
+
NE:
|
615
|
+
- Nebraska
|
616
|
+
- "31"
|
617
|
+
VA:
|
618
|
+
- Virginia
|
619
|
+
- "51"
|
620
|
+
ME:
|
621
|
+
- Maine
|
622
|
+
- "23"
|
637
623
|
MH: Marshall Islands
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
WI: Wisconsin
|
624
|
+
TN:
|
625
|
+
- Tennessee
|
626
|
+
- "47"
|
627
|
+
LA:
|
628
|
+
- Louisiana
|
629
|
+
- "22"
|
630
|
+
MS:
|
631
|
+
- Mississippi
|
632
|
+
- "28"
|
633
|
+
PA:
|
634
|
+
- Pennsylvania
|
635
|
+
- "42"
|
636
|
+
ND:
|
637
|
+
- North Dakota
|
638
|
+
- "38"
|
654
639
|
AS: American Samoa
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
LA: Louisiana
|
668
|
-
NC: North Carolina
|
640
|
+
SC:
|
641
|
+
- South Carolina
|
642
|
+
- "45"
|
643
|
+
NC:
|
644
|
+
- North Carolina
|
645
|
+
- "37"
|
646
|
+
KY:
|
647
|
+
- Kentucky
|
648
|
+
- "21"
|
649
|
+
MI:
|
650
|
+
- Michigan
|
651
|
+
- "26"
|
669
652
|
AE: Armed Forces
|
653
|
+
DE:
|
654
|
+
- Delaware
|
655
|
+
- "10"
|
656
|
+
MO:
|
657
|
+
- Missouri
|
658
|
+
- "29"
|
659
|
+
VT:
|
660
|
+
- Vermont
|
661
|
+
- "50"
|
662
|
+
WI:
|
663
|
+
- Wisconsin
|
664
|
+
- "55"
|
665
|
+
OH:
|
666
|
+
- Ohio
|
667
|
+
- "39"
|
668
|
+
UT:
|
669
|
+
- Utah
|
670
|
+
- "49"
|
671
|
+
NY:
|
672
|
+
- New York
|
673
|
+
- "36"
|
674
|
+
SD:
|
675
|
+
- South Dakota
|
676
|
+
- "46"
|
677
|
+
DC:
|
678
|
+
- District of Columbia
|
679
|
+
- "11"
|
680
|
+
AL:
|
681
|
+
- Alabama
|
682
|
+
- "01"
|
683
|
+
VI: Virgin Islands
|
684
|
+
GA:
|
685
|
+
- Georgia
|
686
|
+
- "13"
|
687
|
+
TX:
|
688
|
+
- Texas
|
689
|
+
- "48"
|
690
|
+
WY:
|
691
|
+
- Wyoming
|
692
|
+
- "56"
|
693
|
+
IL:
|
694
|
+
- Illinois
|
695
|
+
- "17"
|
696
|
+
AR:
|
697
|
+
- Arkansas
|
698
|
+
- "05"
|
699
|
+
RI:
|
700
|
+
- Rhode Island
|
701
|
+
- "44"
|
702
|
+
AZ:
|
703
|
+
- Arizona
|
704
|
+
- "04"
|
705
|
+
OR:
|
706
|
+
- Oregon
|
707
|
+
- "41"
|
708
|
+
CA:
|
709
|
+
- California
|
710
|
+
- "06"
|
711
|
+
IN:
|
712
|
+
- Indiana
|
713
|
+
- "18"
|
714
|
+
CO:
|
715
|
+
- Colorado
|
716
|
+
- 08
|
717
|
+
PW: Palau
|
718
|
+
MD:
|
719
|
+
- Maryland
|
720
|
+
- "24"
|
721
|
+
WA:
|
722
|
+
- Washington
|
723
|
+
- "53"
|
724
|
+
CT:
|
725
|
+
- Connecticut
|
726
|
+
- 09
|
727
|
+
WV:
|
728
|
+
- West Virginia
|
729
|
+
- "54"
|
730
|
+
FL:
|
731
|
+
- Florida
|
732
|
+
- "12"
|
733
|
+
HI:
|
734
|
+
- Hawaii
|
735
|
+
- "15"
|
736
|
+
ID:
|
737
|
+
- Idaho
|
738
|
+
- "16"
|
739
|
+
NM:
|
740
|
+
- New Mexico
|
741
|
+
- "35"
|
742
|
+
MN:
|
743
|
+
- Minnesota
|
744
|
+
- "27"
|
745
|
+
GU: Guam
|
746
|
+
MA:
|
747
|
+
- Massachusetts
|
748
|
+
- "25"
|
749
|
+
AK:
|
750
|
+
- Alaska
|
751
|
+
- "02"
|
752
|
+
NJ:
|
753
|
+
- New Jersey
|
754
|
+
- "34"
|
755
|
+
PR:
|
756
|
+
- Puerto Rico
|
757
|
+
- "72"
|
758
|
+
FM: Federated States Of Micronesia
|
759
|
+
NV:
|
760
|
+
- Nevada
|
761
|
+
- "32"
|
762
|
+
IA:
|
763
|
+
- Iowa
|
764
|
+
- "19"
|
765
|
+
KS:
|
766
|
+
- Kansas
|
767
|
+
- "20"
|
768
|
+
OK:
|
769
|
+
- Oklahoma
|
770
|
+
- "40"
|
771
|
+
NH:
|
772
|
+
- New Hampshire
|
773
|
+
- "33"
|
670
774
|
BV:
|
671
775
|
:name: Bouvet Island
|
672
776
|
:states: {}
|
@@ -10,7 +10,7 @@ class CountriesTest < Test::Unit::TestCase
|
|
10
10
|
Decoder.i18n = :en
|
11
11
|
end
|
12
12
|
|
13
|
-
context "
|
13
|
+
context "A new object" do
|
14
14
|
should "load the yaml" do
|
15
15
|
Decoder.expects(:load_yaml).returns({:en => {"US" => {:name => "United States", :states => {"MA" => "Massachusetts"}}}})
|
16
16
|
countries = Decoder::Countries.new
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class CountryTest < Test::Unit::TestCase
|
4
|
-
|
5
4
|
should "include 'Common Methods' module" do
|
6
5
|
assert_contains Decoder::State.included_modules, CommonMethods
|
7
6
|
end
|
@@ -24,27 +23,46 @@ class CountryTest < Test::Unit::TestCase
|
|
24
23
|
setup do
|
25
24
|
@country = Decoder::Country.new(:code => "US", :name => "United States")
|
26
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
|
27
33
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
32
39
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
37
45
|
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
41
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
|
42
59
|
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
46
65
|
end
|
47
|
-
|
48
66
|
end
|
49
67
|
|
50
68
|
context "#states" do
|
@@ -52,10 +70,18 @@ class CountryTest < Test::Unit::TestCase
|
|
52
70
|
@country = Decoder::Country.new(:code => "US", :name => "United States")
|
53
71
|
end
|
54
72
|
|
55
|
-
|
56
|
-
|
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
|
57
77
|
end
|
58
|
-
|
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
|
+
|
59
85
|
context "aliases" do
|
60
86
|
should "be equal for #states and #counties" do
|
61
87
|
assert_equal @country.states, @country.counties
|
data/test/states/state_test.rb
CHANGED
@@ -24,6 +24,21 @@ class StateTest < Test::Unit::TestCase
|
|
24
24
|
assert_equal "MA", @state.code
|
25
25
|
end
|
26
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
|
27
42
|
end
|
28
43
|
|
29
44
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 63
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
version: 0.8.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian Cardarella
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-12 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -66,8 +66,8 @@ homepage: http://github.com/bcardarella/decoder
|
|
66
66
|
licenses: []
|
67
67
|
|
68
68
|
post_install_message:
|
69
|
-
rdoc_options:
|
70
|
-
|
69
|
+
rdoc_options: []
|
70
|
+
|
71
71
|
require_paths:
|
72
72
|
- lib
|
73
73
|
required_ruby_version: !ruby/object:Gem::Requirement
|