united_states 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +16 -0
- data/lib/united_states/designations.yml +101 -0
- data/lib/united_states/state/designation.rb +24 -6
- data/lib/united_states/state/name.rb +1 -1
- data/lib/united_states/state/postal_code.rb +3 -3
- data/lib/united_states/version.rb +1 -1
- data/lib/united_states.rb +63 -108
- data/united_states.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a3034a514f527ccbdfb782831ecdb9533d6fe0b
|
4
|
+
data.tar.gz: 5b7138644b59f2744b132d0f4d1cfc9b0b2869b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d55886c4f01615d253c2bea4376d7b6193aaa5f9a73d7fd7d885e707b7b684d6a8747705c515c34ad7f1ce2dc34464508aab75f5cf76e2c8aeda676a5cd3c367
|
7
|
+
data.tar.gz: 49982128640592902bcaad9ec2cf9901af92da149010d0c9330b90982841d65614a0ae85ba2a7b331e9cc7209a28d78e51b6c7d0f202b3c92614acb5daa5cb77
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -10,6 +10,22 @@ __Change Groups__:
|
|
10
10
|
|
11
11
|
## [Unreleased]
|
12
12
|
|
13
|
+
## [1.2.0] - 2017-02-26
|
14
|
+
### Added
|
15
|
+
- `UnitedStates.config_path`
|
16
|
+
- `UnitedStates.array_from_yaml_file(path:)`
|
17
|
+
- `UnitedStates.array_from_yaml(yaml)`
|
18
|
+
- `UnitedStates.array_from_hashes(*hashes)`
|
19
|
+
- `UnitedStates::State::Designation.from_hash(**hash)`
|
20
|
+
- Example of `UnitedStates::State::Designation#initialize(...)`
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
- `UnitedStates.all` to use `UnitedStates.array_from_yaml_file(path:)`
|
24
|
+
|
25
|
+
### Fixed
|
26
|
+
- `Designation`, `Name`, and `PostalCode` yard documentation typos.
|
27
|
+
- `"Abbrevation"` typos, now `"PostalCode"`.
|
28
|
+
|
13
29
|
## [1.1.1] - 2017-02-18
|
14
30
|
### Added
|
15
31
|
- `CircleCI` now tests against `Ruby` versions `2.1.10`, `2.2.6`, `2.3.3`, `2.4.0`.
|
@@ -0,0 +1,101 @@
|
|
1
|
+
---
|
2
|
+
Alabama:
|
3
|
+
postal_code: AL
|
4
|
+
Alaska:
|
5
|
+
postal_code: AK
|
6
|
+
Arizona:
|
7
|
+
postal_code: AZ
|
8
|
+
Arkansas:
|
9
|
+
postal_code: AR
|
10
|
+
California:
|
11
|
+
postal_code: CA
|
12
|
+
Colorado:
|
13
|
+
postal_code: CO
|
14
|
+
Connecticut:
|
15
|
+
postal_code: CT
|
16
|
+
Delaware:
|
17
|
+
postal_code: DE
|
18
|
+
Florida:
|
19
|
+
postal_code: FL
|
20
|
+
Georgia:
|
21
|
+
postal_code: GA
|
22
|
+
Hawaii:
|
23
|
+
postal_code: HI
|
24
|
+
Idaho:
|
25
|
+
postal_code: ID
|
26
|
+
Illinois:
|
27
|
+
postal_code: IL
|
28
|
+
Indiana:
|
29
|
+
postal_code: IN
|
30
|
+
Iowa:
|
31
|
+
postal_code: IA
|
32
|
+
Kansas:
|
33
|
+
postal_code: KS
|
34
|
+
Kentucky:
|
35
|
+
postal_code: KY
|
36
|
+
Louisiana:
|
37
|
+
postal_code: LA
|
38
|
+
Maine:
|
39
|
+
postal_code: ME
|
40
|
+
Maryland:
|
41
|
+
postal_code: MD
|
42
|
+
Massachusetts:
|
43
|
+
postal_code: MA
|
44
|
+
Michigan:
|
45
|
+
postal_code: MI
|
46
|
+
Minnesota:
|
47
|
+
postal_code: MN
|
48
|
+
Mississippi:
|
49
|
+
postal_code: MS
|
50
|
+
Missouri:
|
51
|
+
postal_code: MO
|
52
|
+
Montana:
|
53
|
+
postal_code: MT
|
54
|
+
Nebraska:
|
55
|
+
postal_code: NE
|
56
|
+
Nevada:
|
57
|
+
postal_code: NV
|
58
|
+
New Hampshire:
|
59
|
+
postal_code: NH
|
60
|
+
New Jersey:
|
61
|
+
postal_code: NJ
|
62
|
+
New Mexico:
|
63
|
+
postal_code: NM
|
64
|
+
New York:
|
65
|
+
postal_code: NY
|
66
|
+
North Carolina:
|
67
|
+
postal_code: NC
|
68
|
+
North Dakota:
|
69
|
+
postal_code: ND
|
70
|
+
Ohio:
|
71
|
+
postal_code: OH
|
72
|
+
Oklahoma:
|
73
|
+
postal_code: OK
|
74
|
+
Oregon:
|
75
|
+
postal_code: OR
|
76
|
+
Pennsylvania:
|
77
|
+
postal_code: PA
|
78
|
+
Rhode Island:
|
79
|
+
postal_code: RI
|
80
|
+
South Carolina:
|
81
|
+
postal_code: SC
|
82
|
+
South Dakota:
|
83
|
+
postal_code: SD
|
84
|
+
Tennessee:
|
85
|
+
postal_code: TN
|
86
|
+
Texas:
|
87
|
+
postal_code: TX
|
88
|
+
Utah:
|
89
|
+
postal_code: UT
|
90
|
+
Vermont:
|
91
|
+
postal_code: VT
|
92
|
+
Virginia:
|
93
|
+
postal_code: VA
|
94
|
+
Washington:
|
95
|
+
postal_code: WA
|
96
|
+
West Virginia:
|
97
|
+
postal_code: WV
|
98
|
+
Wisconsin:
|
99
|
+
postal_code: WI
|
100
|
+
Wyoming:
|
101
|
+
postal_code: WY
|
@@ -6,16 +6,34 @@ module UnitedStates
|
|
6
6
|
module State
|
7
7
|
# Represents the various way to designate a state (e.g. name, postal code).
|
8
8
|
class Designation
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# the state's postal code
|
9
|
+
# @return [UnitedStates::State::PostalCode]
|
10
|
+
# the state's postal code
|
12
11
|
attr_reader :postal_code
|
13
12
|
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# the state's name
|
13
|
+
# @return [UnitedStates::State::Name]
|
14
|
+
# the state's name
|
17
15
|
attr_reader :name
|
18
16
|
|
17
|
+
# @example From Named Parameters
|
18
|
+
# UnitedStates::State::Designation.from_hash(
|
19
|
+
# name: 'Hawaii', postal_code: 'HI')
|
20
|
+
# # => #<UnitedStates::State::Designation:0x...@string="HI">>
|
21
|
+
# @example From Variable
|
22
|
+
# hawaii_hash = { name: 'Hawaii', postal_code: 'HI' }
|
23
|
+
# UnitedStates::State::Designation.from_hash(hawaii_hash)
|
24
|
+
# # => #<UnitedStates::State::Designation:0x...@string="HI">>
|
25
|
+
# @param hash [Hash]
|
26
|
+
# a hash of Designation attributes, see {#initialize} for parameters
|
27
|
+
# @return [UnitedStates::State::Designation]
|
28
|
+
# a Designation with attributes provided via hash
|
29
|
+
def self.from_hash(**hash)
|
30
|
+
new(name: hash[:name], postal_code: hash[:postal_code])
|
31
|
+
end
|
32
|
+
|
33
|
+
# @example
|
34
|
+
# UnitedStates::State::Designation.new(
|
35
|
+
# name: 'wyoming', postal_code: 'wy')
|
36
|
+
# # => #<UnitedStates::State::Designation:0x007...@string="wy">>
|
19
37
|
# @param name [String]
|
20
38
|
# @param postal_code [String]
|
21
39
|
# @raise [UnitedStates::State::PostalCode::StringTooLongError]
|
@@ -40,7 +40,7 @@ module UnitedStates
|
|
40
40
|
@string = string
|
41
41
|
end
|
42
42
|
|
43
|
-
# @param [UnitedStates::State::PostalCode]
|
43
|
+
# @param other [UnitedStates::State::PostalCode]
|
44
44
|
# @return [Boolean]
|
45
45
|
# whether or not other.to_s matches self.to_s
|
46
46
|
def ==(other)
|
@@ -48,13 +48,13 @@ module UnitedStates
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# @return [String]
|
51
|
-
# an all lowercase version of this
|
51
|
+
# an all lowercase version of this PostalCode
|
52
52
|
def lowercase
|
53
53
|
@string.downcase
|
54
54
|
end
|
55
55
|
|
56
56
|
# @return [String]
|
57
|
-
# an all uppercase version of this
|
57
|
+
# an all uppercase version of this PostalCode
|
58
58
|
def uppercase
|
59
59
|
@string.upcase
|
60
60
|
end
|
data/lib/united_states.rb
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
require 'united_states/version'
|
3
3
|
require 'united_states/state/designation'
|
4
4
|
|
5
|
-
# rubocop: disable Metrics/ModuleLength
|
6
|
-
#
|
7
5
|
# Top-level namespace for this gem.
|
8
6
|
module UnitedStates
|
9
7
|
# Thrown when someone attempts to search for a state with
|
@@ -32,116 +30,73 @@ module UnitedStates
|
|
32
30
|
find_by_postal_code(name_or_postal_code)
|
33
31
|
end
|
34
32
|
|
35
|
-
# rubocop: disable Metrics/AbcSize
|
36
|
-
# rubocop: disable Metrics/MethodLength
|
37
33
|
# @return [Array<UnitedStates::State::Designation>]
|
38
34
|
# a collection of all U.S. State Designations.
|
39
35
|
def self.all
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
UnitedStates::State::Designation.
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
UnitedStates::State::Designation.new(
|
104
|
-
name: 'New York', postal_code: 'NY'),
|
105
|
-
UnitedStates::State::Designation.new(
|
106
|
-
name: 'North Carolina', postal_code: 'NC'),
|
107
|
-
UnitedStates::State::Designation.new(
|
108
|
-
name: 'North Dakota', postal_code: 'ND'),
|
109
|
-
UnitedStates::State::Designation.new(
|
110
|
-
name: 'Ohio', postal_code: 'OH'),
|
111
|
-
UnitedStates::State::Designation.new(
|
112
|
-
name: 'Oklahoma', postal_code: 'OK'),
|
113
|
-
UnitedStates::State::Designation.new(
|
114
|
-
name: 'Oregon', postal_code: 'OR'),
|
115
|
-
UnitedStates::State::Designation.new(
|
116
|
-
name: 'Pennsylvania', postal_code: 'PA'),
|
117
|
-
UnitedStates::State::Designation.new(
|
118
|
-
name: 'Rhode Island', postal_code: 'RI'),
|
119
|
-
UnitedStates::State::Designation.new(
|
120
|
-
name: 'South Carolina', postal_code: 'SC'),
|
121
|
-
UnitedStates::State::Designation.new(
|
122
|
-
name: 'South Dakota', postal_code: 'SD'),
|
123
|
-
UnitedStates::State::Designation.new(
|
124
|
-
name: 'Tennessee', postal_code: 'TN'),
|
125
|
-
UnitedStates::State::Designation.new(
|
126
|
-
name: 'Texas', postal_code: 'TX'),
|
127
|
-
UnitedStates::State::Designation.new(
|
128
|
-
name: 'Utah', postal_code: 'UT'),
|
129
|
-
UnitedStates::State::Designation.new(
|
130
|
-
name: 'Vermont', postal_code: 'VT'),
|
131
|
-
UnitedStates::State::Designation.new(
|
132
|
-
name: 'Virginia', postal_code: 'VA'),
|
133
|
-
UnitedStates::State::Designation.new(
|
134
|
-
name: 'Washington', postal_code: 'WA'),
|
135
|
-
UnitedStates::State::Designation.new(
|
136
|
-
name: 'West Virginia', postal_code: 'WV'),
|
137
|
-
UnitedStates::State::Designation.new(
|
138
|
-
name: 'Wisconsin', postal_code: 'WI'),
|
139
|
-
UnitedStates::State::Designation.new(
|
140
|
-
name: 'Wyoming', postal_code: 'WY')
|
141
|
-
]
|
36
|
+
array_from_yaml_file(path: config_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @example
|
40
|
+
# UnitedStates.array_from_hashes(
|
41
|
+
# { name: 'Florida', postal_code: 'FL' },
|
42
|
+
# { name: 'Iowa', postal_code: 'IA'})
|
43
|
+
# @param hashes [Array<Hash>]
|
44
|
+
# a collection of attributes as hashes
|
45
|
+
# @return [Array<UnitedStates::State::Designation>]
|
46
|
+
# a collection of state designations made from the given hash attributes
|
47
|
+
def self.array_from_hashes(*hashes)
|
48
|
+
hashes.map do |hash|
|
49
|
+
UnitedStates::State::Designation.from_hash(hash)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# @example
|
54
|
+
# require 'united_states'
|
55
|
+
#
|
56
|
+
# UnitedStates.array_from_yaml(
|
57
|
+
# { Washington: { postal_code: 'WA' } }.to_yaml)
|
58
|
+
# # => [<UnitedStates::State::Designation...>]
|
59
|
+
# @param yaml [String]
|
60
|
+
# a String representation of YAML.
|
61
|
+
# @return [Array<UnitedStates::State::Designation>]
|
62
|
+
# a collection of state designations made from the given hash attributes
|
63
|
+
# @raise UnitedStates::State::PostalCode::StringTooLongError
|
64
|
+
# if a designation has a postal code that too long
|
65
|
+
# @raise UnitedStates::State::PostalCode::StringTooShortError
|
66
|
+
# if a designation has no postal code defined or is too short
|
67
|
+
def self.array_from_yaml(yaml)
|
68
|
+
return [] unless YAML.safe_load(yaml)
|
69
|
+
YAML.safe_load(yaml).map do |key, value|
|
70
|
+
UnitedStates::State::Designation.new(
|
71
|
+
name: key, postal_code: value && value.fetch('postal_code', ''))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# @example
|
76
|
+
# require 'united_states'
|
77
|
+
#
|
78
|
+
# UnitedStates.array_from_yaml_file(path: './states.yml')
|
79
|
+
# # => [<UnitedStates::State::Designation...>]
|
80
|
+
# @param path [String]
|
81
|
+
# the path to the YAML file
|
82
|
+
# @return [Array<UnitedStates::State::Designation>]
|
83
|
+
# a collection of state designations made from the YAML file
|
84
|
+
# @raise UnitedStates::State::PostalCode::StringTooLongError
|
85
|
+
# if a designation has a postal code that too long
|
86
|
+
# @raise UnitedStates::State::PostalCode::StringTooShortError
|
87
|
+
# if a designation has no postal code defined or is too short
|
88
|
+
def self.array_from_yaml_file(path:)
|
89
|
+
pathname = Pathname.new(path)
|
90
|
+
return array_from_yaml(pathname.read) if pathname.exist?
|
91
|
+
raise "\"#{path}\" does not exist.\n"\
|
92
|
+
'Please supply a path to a YAML file.'
|
93
|
+
end
|
94
|
+
|
95
|
+
# @return [String]
|
96
|
+
# the path to the Designations yaml file
|
97
|
+
def self.config_path
|
98
|
+
'./lib/united_states/designations.yml'
|
142
99
|
end
|
143
|
-
# rubocop: enable Metrics/AbcSize
|
144
|
-
# rubocop: enable Metrics/MethodLength
|
145
100
|
|
146
101
|
# @example
|
147
102
|
# UnitedStates.find_by_name('louisiana') # => UnitedSt...Designation
|
data/united_states.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
27
27
|
spec.add_development_dependency 'faker'
|
28
28
|
spec.add_development_dependency 'pry'
|
29
|
+
spec.add_development_dependency 'pry-byebug'
|
29
30
|
spec.add_development_dependency 'pry-coolline'
|
30
31
|
spec.add_development_dependency 'rake', '~> 10.0'
|
31
32
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: united_states
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Whittington
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: pry-coolline
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,6 +188,7 @@ files:
|
|
174
188
|
- bin/test
|
175
189
|
- circle.yml
|
176
190
|
- lib/united_states.rb
|
191
|
+
- lib/united_states/designations.yml
|
177
192
|
- lib/united_states/state/designation.rb
|
178
193
|
- lib/united_states/state/name.rb
|
179
194
|
- lib/united_states/state/postal_code.rb
|