postal_code 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.rdoc +34 -9
- data/Rakefile +20 -22
- data/db/US.tsv +1004 -510
- data/lib/postal_code.rb +11 -7
- data/postal_code.gemspec +16 -6
- data/test/test_postal_code.rb +19 -12
- metadata +14 -11
data/lib/postal_code.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module PostalCode
|
2
2
|
|
3
|
-
VERSION = '0.
|
3
|
+
VERSION = '0.4.0'
|
4
4
|
|
5
5
|
CityOffset = 0
|
6
6
|
StateOffset = 1
|
@@ -45,13 +45,17 @@ module PostalCode
|
|
45
45
|
end
|
46
46
|
|
47
47
|
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
48
|
+
# Postal codes must be strings because:
|
49
|
+
# 1. Postal codes are not calculable, therefore should not be numeric.
|
50
|
+
# 2. A postal code with a leading zero would be an octal. However, *08880* is
|
51
|
+
# an invalid octal numeric, yet a valid postal code.
|
52
52
|
#
|
53
53
|
def self.valid_format? postal_code
|
54
|
-
postal_code
|
54
|
+
unless postal_code.is_a? String
|
55
|
+
raise(TypeError, "postal code must be a string")
|
56
|
+
end
|
57
|
+
|
58
|
+
(postal_code =~ /^\d{5}(-\d{4})?$/) ? true : false
|
55
59
|
end
|
56
60
|
|
57
61
|
#
|
@@ -74,6 +78,6 @@ module PostalCode
|
|
74
78
|
end
|
75
79
|
end
|
76
80
|
|
77
|
-
private_class_method :fetch
|
81
|
+
private_class_method :fetch
|
78
82
|
|
79
83
|
end
|
data/postal_code.gemspec
CHANGED
@@ -2,11 +2,21 @@ Gem::Specification.new('postal_code') do |s|
|
|
2
2
|
s.version = File.read('lib/postal_code.rb')[/VERSION = '(.*)'/, 1]
|
3
3
|
s.author = 'Clint Pachl'
|
4
4
|
s.email = 'pachl@ecentryx.com'
|
5
|
-
s.homepage = '
|
5
|
+
s.homepage = 'https://ecentryx.com/gems/postal_code'
|
6
6
|
s.license = 'ISC'
|
7
|
-
s.summary = 'Postal Code Resolver'
|
8
|
-
s.description = '
|
9
|
-
s.files = Dir[
|
10
|
-
|
11
|
-
|
7
|
+
s.summary = 'Postal (ZIP) Code Resolver'
|
8
|
+
s.description = 'Resolve a postal (ZIP) code to a corresponding city or state.'
|
9
|
+
s.files = Dir[
|
10
|
+
'Rakefile',
|
11
|
+
'README*',
|
12
|
+
'*.gemspec',
|
13
|
+
'lib/**/*.rb',
|
14
|
+
'test/**/*',
|
15
|
+
'db/*.tsv'
|
16
|
+
]
|
17
|
+
s.extra_rdoc_files = ['README.rdoc']
|
18
|
+
s.rdoc_options = [
|
19
|
+
'--title', "A Ruby #{s.summary}",
|
20
|
+
'--main', 'README.rdoc'
|
21
|
+
]
|
12
22
|
end
|
data/test/test_postal_code.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'postal_code'
|
3
3
|
|
4
|
-
class PostalCodeTest < Minitest::
|
4
|
+
class PostalCodeTest < Minitest::Test
|
5
5
|
|
6
6
|
ProductionDB = PostalCode::DB.dup
|
7
7
|
TestDB = File.dirname(__FILE__) + '/data/US.tsv'
|
@@ -43,8 +43,8 @@ class PostalCodeTest < Minitest::Unit::TestCase
|
|
43
43
|
|
44
44
|
def test_postal_code_not_found_in_any_city
|
45
45
|
pcode = '99999'
|
46
|
-
|
47
|
-
|
46
|
+
assert_nil PostalCode.city(pcode)
|
47
|
+
assert_nil PostalCode.state(pcode)
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_reactive_cache
|
@@ -72,15 +72,22 @@ class PostalCodeTest < Minitest::Unit::TestCase
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_postal_code_validations
|
75
|
-
|
76
|
-
refute PostalCode.
|
77
|
-
refute PostalCode.
|
78
|
-
|
79
|
-
|
80
|
-
assert PostalCode.
|
81
|
-
|
82
|
-
|
83
|
-
|
75
|
+
assert PostalCode.valid_format?('01234-1234')
|
76
|
+
refute PostalCode.valid_format?('01234-123')
|
77
|
+
refute PostalCode.valid_format?('01234-12')
|
78
|
+
refute PostalCode.valid_format?('01234-1')
|
79
|
+
refute PostalCode.valid_format?('01234-')
|
80
|
+
assert PostalCode.valid_format?('01234')
|
81
|
+
refute PostalCode.valid_format?('0123')
|
82
|
+
refute PostalCode.valid_format?('012')
|
83
|
+
refute PostalCode.valid_format?('01')
|
84
|
+
refute PostalCode.valid_format?('0')
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_postal_code_validation_exceptions
|
88
|
+
assert_raises(TypeError) { PostalCode.valid_format? 99999 }
|
89
|
+
assert_raises(TypeError) { PostalCode.valid_format? 00001 }
|
90
|
+
assert_raises(TypeError) { PostalCode.valid_format? 1 }
|
84
91
|
end
|
85
92
|
|
86
93
|
end
|
metadata
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postal_code
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clint Pachl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: Resolve a postal (ZIP) code to a corresponding city or state.
|
14
14
|
email: pachl@ecentryx.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
|
-
extra_rdoc_files:
|
17
|
+
extra_rdoc_files:
|
18
|
+
- README.rdoc
|
18
19
|
files:
|
19
20
|
- README.rdoc
|
20
21
|
- Rakefile
|
@@ -24,12 +25,16 @@ files:
|
|
24
25
|
- postal_code.gemspec
|
25
26
|
- test/data/US.tsv
|
26
27
|
- test/test_postal_code.rb
|
27
|
-
homepage:
|
28
|
+
homepage: https://ecentryx.com/gems/postal_code
|
28
29
|
licenses:
|
29
30
|
- ISC
|
30
31
|
metadata: {}
|
31
32
|
post_install_message:
|
32
|
-
rdoc_options:
|
33
|
+
rdoc_options:
|
34
|
+
- "--title"
|
35
|
+
- A Ruby Postal (ZIP) Code Resolver
|
36
|
+
- "--main"
|
37
|
+
- README.rdoc
|
33
38
|
require_paths:
|
34
39
|
- lib
|
35
40
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -43,10 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
48
|
- !ruby/object:Gem::Version
|
44
49
|
version: '0'
|
45
50
|
requirements: []
|
46
|
-
|
47
|
-
rubygems_version: 2.5.1
|
51
|
+
rubygems_version: 3.0.3
|
48
52
|
signing_key:
|
49
53
|
specification_version: 4
|
50
|
-
summary: Postal Code Resolver
|
51
|
-
test_files:
|
52
|
-
- test/test_postal_code.rb
|
54
|
+
summary: Postal (ZIP) Code Resolver
|
55
|
+
test_files: []
|