us_states_enhanced 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b1bd63833f28d203b5d1848dabbd1b17e747d9e2
4
+ data.tar.gz: 87307c1c3f9ffbe6e27c5a5b8783a529609d8f0d
5
+ SHA512:
6
+ metadata.gz: 946449cbc76f225c342258cbc6876af895babd0110787b0ce8a03d4c39892d6e59bc69a14e702ee8389776fbabb081306927f83c41d6326e8991bd4405daa352
7
+ data.tar.gz: f067538b8b4e8f5566e32d4a90337487545135d384b73104e8dbdf5b694acec6fafad464980883d91a4f076f363c63db8921b89eaa2f08d7fdc0efe2aba2d32e
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec"
10
+ gem "yard"
11
+ gem "bundler"
12
+ gem "jeweler"
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Byron Anderson
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.md ADDED
@@ -0,0 +1,21 @@
1
+ US States: Enhanced
2
+ ====================
3
+
4
+ This is a repackage of Byron Anderson's original gem.
5
+
6
+ Installing
7
+ ----------
8
+ `gem install us_states_enhanced`
9
+
10
+ or in your Gemfile:
11
+
12
+ `gem 'us_states_enhanced'`
13
+
14
+ Credits
15
+ -------
16
+
17
+ * Byron Anderson for the original us_states gem.
18
+
19
+
20
+ See LICENSE.txt for further details.
21
+
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "us_states_enhanced"
18
+ gem.homepage = "http://github.com/c4eo/us_states_enhanced"
19
+ gem.license = "MIT"
20
+ gem.summary = "A module containing a list of all of the United States and territories"
21
+ gem.description = "As simple as that"
22
+ gem.email = "mpatterson@skillsengine.com"
23
+ gem.authors = ["Byron Anderson", "Jim Gilliam", "Matt E. Patterson"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'yard'
42
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,161 @@
1
+ module State
2
+ class InvalidState < RuntimeError; end
3
+
4
+ STFIPS = [
5
+ ["Alabama", 1],
6
+ ["Alaska", 2],
7
+ ["Arizona", 4],
8
+ ["Arkansas", 5],
9
+ ["California", 6],
10
+ ["Colorado", 8],
11
+ ["Connecticut", 9],
12
+ ["Delaware", 10],
13
+ ["District of Columbia", 11],
14
+ ["Florida", 12],
15
+ ["Georgia", 13],
16
+ ["Guam", 66],
17
+ ["Hawaii", 15],
18
+ ["Idaho", 16],
19
+ ["Illinois", 17],
20
+ ["Indiana", 18],
21
+ ["Iowa", 19],
22
+ ["Kansas", 20],
23
+ ["Kentucky", 21],
24
+ ["Louisiana", 22],
25
+ ["Maine", 23],
26
+ ["Maryland", 24],
27
+ ["Massachusetts", 25],
28
+ ["Michigan", 26],
29
+ ["Minnesota", 27],
30
+ ["Mississippi", 28],
31
+ ["Missouri", 29],
32
+ ["Montana", 30],
33
+ ["Nebraska", 31],
34
+ ["Nevada", 32],
35
+ ["New Hampshire", 33],
36
+ ["New Jersey", 34],
37
+ ["New Mexico", 35],
38
+ ["New York", 36],
39
+ ["North Carolina", 37],
40
+ ["North Dakota", 38],
41
+ ["Ohio", 39],
42
+ ["Oklahoma", 40],
43
+ ["Oregon", 41],
44
+ ["Pennsylvania", 42],
45
+ ["Puerto Rico", 72],
46
+ ["Rhode Island", 44],
47
+ ["South Carolina", 45],
48
+ ["South Dakota", 46],
49
+ ["Tennessee", 47],
50
+ ["Texas", 48],
51
+ ["Virgin Islands", 78],
52
+ ["Utah", 49],
53
+ ["Vermont", 50],
54
+ ["Virginia", 51],
55
+ ["Washington", 53],
56
+ ["West Virginia", 54],
57
+ ["Wisconsin", 55],
58
+ ["Wyoming", 56],
59
+ ]
60
+
61
+ CODES = {
62
+ 'AL' => 'Alabama',
63
+ 'AK' => 'Alaska',
64
+ 'AS' => 'American Samoa',
65
+ 'AZ' => 'Arizona',
66
+ 'AR' => 'Arkansas',
67
+ 'CA' => 'California',
68
+ 'CO' => 'Colorado',
69
+ 'CT' => 'Connecticut',
70
+ 'DE' => 'Delaware',
71
+ 'DC' => 'District of Columbia',
72
+ 'FM' => 'Federated States of Micronesia',
73
+ 'FL' => 'Florida',
74
+ 'GA' => 'Georgia',
75
+ 'GU' => 'Guam',
76
+ 'HI' => 'Hawaii',
77
+ 'ID' => 'Idaho',
78
+ 'IL' => 'Illinois',
79
+ 'IN' => 'Indiana',
80
+ 'IA' => 'Iowa',
81
+ 'KS' => 'Kansas',
82
+ 'KY' => 'Kentucky',
83
+ 'LA' => 'Louisiana',
84
+ 'ME' => 'Maine',
85
+ 'MH' => 'Marshall Islands',
86
+ 'MD' => 'Maryland',
87
+ 'MA' => 'Massachusetts',
88
+ 'MI' => 'Michigan',
89
+ 'MN' => 'Minnesota',
90
+ 'MS' => 'Mississippi',
91
+ 'MO' => 'Missouri',
92
+ 'MT' => 'Montana',
93
+ 'NE' => 'Nebraska',
94
+ 'NV' => 'Nevada',
95
+ 'NH' => 'New Hampshire',
96
+ 'NJ' => 'New Jersey',
97
+ 'NM' => 'New Mexico',
98
+ 'NY' => 'New York',
99
+ 'NC' => 'North Carolina',
100
+ 'ND' => 'North Dakota',
101
+ 'OH' => 'Ohio',
102
+ 'OK' => 'Oklahoma',
103
+ 'OR' => 'Oregon',
104
+ 'PW' => 'Palau',
105
+ 'PA' => 'Pennsylvania',
106
+ 'PR' => 'Puerto Rico',
107
+ 'RI' => 'Rhode Island',
108
+ 'SC' => 'South Carolina',
109
+ 'SD' => 'South Dakota',
110
+ 'TN' => 'Tennessee',
111
+ 'TX' => 'Texas',
112
+ 'UT' => 'Utah',
113
+ 'VT' => 'Vermont',
114
+ 'VI' => 'Virgin Islands',
115
+ 'VA' => 'Virginia',
116
+ 'WA' => 'Washington',
117
+ 'WV' => 'West Virginia',
118
+ 'WI' => 'Wisconsin',
119
+ 'WY' => 'Wyoming'
120
+ }
121
+
122
+
123
+ def self.stfips_by_code(code)
124
+ begin
125
+ state = CODES[code.upcase]
126
+ [STFIPS.assoc(state)].flatten.last || nil
127
+ rescue
128
+ nil
129
+ end
130
+ end
131
+
132
+ def self.stfips(state)
133
+ code = normalize(state)
134
+ stfips_by_code(code)
135
+ end
136
+
137
+ def self.member?(state)
138
+ CODES.member? normalize(state)
139
+ rescue InvalidState
140
+ false
141
+ end
142
+
143
+ def self.states
144
+ CODES.values
145
+ end
146
+
147
+ def self.normalize(state)
148
+ return state.upcase if CODES.member? state.upcase
149
+ return STATE_TO_CODE.fetch state.downcase
150
+ rescue KeyError
151
+ raise InvalidState
152
+ end
153
+
154
+ private
155
+
156
+ STATE_TO_CODE = CODES.inject({}) do |hash, code_state|
157
+ code, state = code_state
158
+ hash[state.downcase] = code
159
+ hash
160
+ end
161
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'us_states_enhanced'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,19 @@
1
+ require 'us_states_enhanced'
2
+
3
+ describe State do
4
+ describe ".normalize" do
5
+ specify { State.normalize("Alabama").should == "AL" }
6
+ specify { State.normalize("AL").should == "AL" }
7
+ specify { State.normalize("texas").should == "TX" }
8
+ specify do
9
+ expect { State.normalize("south") }.to raise_error(State::InvalidState)
10
+ end
11
+ specify { State.normalize("tx").should == "TX" }
12
+ end
13
+
14
+ describe ".member?" do
15
+ specify { State.member?("AL").should be_true }
16
+ specify { State.member?("XT").should be_false }
17
+ specify { State.member?("Alabama").should be_true }
18
+ end
19
+ end
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: us_states_enhanced 0.1.2 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "us_states_enhanced"
9
+ s.version = "0.1.2"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Byron Anderson", "Jim Gilliam", "Matt E. Patterson"]
14
+ s.date = "2015-09-09"
15
+ s.description = "As simple as that"
16
+ s.email = "mpatterson@skillsengine.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ "Gemfile",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/us_states_enhanced.rb",
30
+ "spec/spec_helper.rb",
31
+ "spec/us_states_enhanced_spec.rb",
32
+ "us_states_enhanced.gemspec"
33
+ ]
34
+ s.homepage = "http://github.com/c4eo/us_states_enhanced"
35
+ s.licenses = ["MIT"]
36
+ s.rubygems_version = "2.4.8"
37
+ s.summary = "A module containing a list of all of the United States and territories"
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 4
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_development_dependency(%q<rspec>, [">= 0"])
44
+ s.add_development_dependency(%q<yard>, [">= 0"])
45
+ s.add_development_dependency(%q<bundler>, [">= 0"])
46
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<rspec>, [">= 0"])
49
+ s.add_dependency(%q<yard>, [">= 0"])
50
+ s.add_dependency(%q<bundler>, [">= 0"])
51
+ s.add_dependency(%q<jeweler>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<rspec>, [">= 0"])
55
+ s.add_dependency(%q<yard>, [">= 0"])
56
+ s.add_dependency(%q<bundler>, [">= 0"])
57
+ s.add_dependency(%q<jeweler>, [">= 0"])
58
+ end
59
+ end
60
+
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: us_states_enhanced
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Byron Anderson
8
+ - Jim Gilliam
9
+ - Matt E. Patterson
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2015-09-09 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: yard
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: bundler
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: jeweler
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ description: As simple as that
72
+ email: mpatterson@skillsengine.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files:
76
+ - LICENSE.txt
77
+ - README.md
78
+ files:
79
+ - ".document"
80
+ - ".rspec"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - VERSION
86
+ - lib/us_states_enhanced.rb
87
+ - spec/spec_helper.rb
88
+ - spec/us_states_enhanced_spec.rb
89
+ - us_states_enhanced.gemspec
90
+ homepage: http://github.com/c4eo/us_states_enhanced
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.8
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: A module containing a list of all of the United States and territories
114
+ test_files: []