zip5 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +9 -0
- data/lib/zip5.rb +16 -1
- data/lib/zip5/version.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/zip5_spec.rb +24 -17
- data/zip5.gemspec +1 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7c3edd5d43e8625eb9eb1adf9564483e1211373
|
4
|
+
data.tar.gz: 8e166debb115563f57903d944f03ea947a9afc01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3be32884d951637bbc50ba19cd9bfe2604949ef8b403e4e56d33ae8d7ea7d3129403a6d37b46e6647242da540ea82a3efa4030886194b1dc3439fd76f68e1f6e
|
7
|
+
data.tar.gz: e4bdc489f11582a42816ccf206fe297959b220572a9a3147a9124a3b3136fbd07ce2fabc1570aa7a13c4b5262e1fadb0d6bff1d9c1cb14b3aceb89113dd0522b
|
data/CHANGELOG
ADDED
data/lib/zip5.rb
CHANGED
@@ -4,7 +4,7 @@ module Zip5
|
|
4
4
|
VALID = 501..99950
|
5
5
|
|
6
6
|
def Zip5.zip5(input)
|
7
|
-
input = input.to_i.to_s.
|
7
|
+
input = input.to_i.to_s.gsub('-', '')
|
8
8
|
memo = case input.length
|
9
9
|
when 9
|
10
10
|
input[0,5]
|
@@ -26,4 +26,19 @@ module Zip5
|
|
26
26
|
end
|
27
27
|
memo
|
28
28
|
end
|
29
|
+
|
30
|
+
def Zip5.zip4(input)
|
31
|
+
input = input.to_s.gsub(/\.\d*\z/, '')
|
32
|
+
memo = nil
|
33
|
+
if input =~ /\A\d+\-(\d+)\z/
|
34
|
+
memo = $1.to_i
|
35
|
+
elsif zip5 = zip5(input)
|
36
|
+
hunk = zip5.gsub /\A0*/, ''
|
37
|
+
pat = /\A0*#{hunk}/
|
38
|
+
memo = input.gsub(pat, '').to_i
|
39
|
+
end
|
40
|
+
if memo and memo > 0
|
41
|
+
'%04d' % memo.to_i
|
42
|
+
end
|
43
|
+
end
|
29
44
|
end
|
data/lib/zip5/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/zip5_spec.rb
CHANGED
@@ -2,27 +2,34 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Zip5 do
|
4
4
|
{
|
5
|
-
|
6
|
-
'99950-
|
7
|
-
|
8
|
-
'5753-
|
9
|
-
'05753-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
999500004 => ['99950', '0004'],
|
6
|
+
'99950-0004' => ['99950', '0004'],
|
7
|
+
57530004 => ['05753', '0004'],
|
8
|
+
'5753-0004' => ['05753', '0004'],
|
9
|
+
'05753-0004' => ['05753', '0004'],
|
10
|
+
5010004 => ['00501', '0004'],
|
11
|
+
'99950-4' => ['99950', '0004'],
|
12
|
+
'5753-4' => ['05753', '0004'],
|
13
|
+
'05753-4' => ['05753', '0004'],
|
14
|
+
99950 => ['99950', nil],
|
15
|
+
5753 => ['05753', nil],
|
16
|
+
1000 => ['01000', nil],
|
17
|
+
501 => ['00501', nil],
|
18
|
+
'' => [nil, nil],
|
19
|
+
'abc' => [nil, nil],
|
17
20
|
}.each do |input, expected|
|
18
|
-
it "parses #{input.inspect} as #{expected.
|
19
|
-
|
21
|
+
it "parses #{input.inspect} as #{expected.compact.join('-')}" do
|
22
|
+
zip5, zip4 = expected
|
23
|
+
expect(Zip5.zip5(input)).to eq(zip5)
|
24
|
+
expect(Zip5.zip4(input)).to eq(zip4)
|
20
25
|
end
|
21
|
-
# here we also test
|
26
|
+
# here we also test 57530004.0, etc.
|
22
27
|
if input.is_a?(Integer)
|
23
28
|
input_f = input.to_f
|
24
|
-
it "parses #{input_f.inspect} as #{expected.
|
25
|
-
|
29
|
+
it "parses #{input_f.inspect} as #{expected.compact.join('-')}" do
|
30
|
+
zip5, zip4 = expected
|
31
|
+
expect(Zip5.zip5(input_f)).to eq(zip5)
|
32
|
+
expect(Zip5.zip4(input_f)).to eq(zip4)
|
26
33
|
end
|
27
34
|
end
|
28
35
|
end
|
data/zip5.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zip5
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seamus Abshere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-02 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
|
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
|
description: For example, 8840 means 08840 and 5011234 means 00501-1234.
|
56
70
|
email:
|
57
71
|
- seamus@abshere.net
|
@@ -62,6 +76,7 @@ files:
|
|
62
76
|
- ".gitignore"
|
63
77
|
- ".rspec"
|
64
78
|
- ".travis.yml"
|
79
|
+
- CHANGELOG
|
65
80
|
- Gemfile
|
66
81
|
- LICENSE.txt
|
67
82
|
- README.md
|
@@ -91,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
106
|
version: '0'
|
92
107
|
requirements: []
|
93
108
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.5.1
|
95
110
|
signing_key:
|
96
111
|
specification_version: 4
|
97
112
|
summary: Convert United States zip codes to their correct Zip5 representation, even
|