zip5 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +63 -0
- data/Rakefile +7 -0
- data/lib/zip5.rb +29 -0
- data/lib/zip5/version.rb +3 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/zip5_spec.rb +29 -0
- data/zip5.gemspec +24 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3982f4dded1b426a7add3df82e08a9affe2f885b
|
4
|
+
data.tar.gz: 850bdc085e5cc52678f2e7335c5fd0cd8374cdc1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3a66e397971e788e8ea1a68c4bf43fc9e69cd6a9f57eeda37249746b1ed74415c1b88fdb47a1312aa09f8ea98cf8d7ef82155c480f655a4019f3f7616487ef3
|
7
|
+
data.tar.gz: 4fc6495ba4f502c46dd397c9f6fd31262055c6d8eb3124ae1f5741dbf8e916f627abdb8c82f41949fd288607ac07a17021726681640f8265131324dfae04f185
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Seamus Abshere
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Zip5
|
2
|
+
|
3
|
+
Convert United States zip codes to their correct Zip5 representation, even if they're missing a leading zero and/or they have the +4 suffix.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'zip5'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install zip5
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Here it is in action:
|
22
|
+
|
23
|
+
```
|
24
|
+
>> Zip5.zip5(53703) # Madison, WI
|
25
|
+
=> "53703"
|
26
|
+
>> Zip5.zip5(8840) # Metuchen, NJ (missing a leading 0)
|
27
|
+
=> "08840"
|
28
|
+
>> Zip5.zip5(5011234) # Holtsville, NY (missing a leading 0 AND with a +4 suffix, i.e. 00501-1234)
|
29
|
+
=> "00501"
|
30
|
+
```
|
31
|
+
|
32
|
+
Here's the output of the test suite:
|
33
|
+
|
34
|
+
```
|
35
|
+
Zip5
|
36
|
+
parses 999501234 as "99950"
|
37
|
+
parses 999501234.0 as "99950"
|
38
|
+
parses "99950-1234" as "99950"
|
39
|
+
parses 57531234 as "05753"
|
40
|
+
parses 57531234.0 as "05753"
|
41
|
+
parses "5753-1234" as "05753"
|
42
|
+
parses "05753-1234" as "05753"
|
43
|
+
parses 5011234 as "00501"
|
44
|
+
parses 5011234.0 as "00501"
|
45
|
+
parses 99950 as "99950"
|
46
|
+
parses 99950.0 as "99950"
|
47
|
+
parses 5753 as "05753"
|
48
|
+
parses 5753.0 as "05753"
|
49
|
+
parses 1000 as "01000"
|
50
|
+
parses 1000.0 as "01000"
|
51
|
+
parses 501 as "00501"
|
52
|
+
parses 501.0 as "00501"
|
53
|
+
parses "" as nil
|
54
|
+
parses "abc" as nil
|
55
|
+
```
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
1. Fork it ( https://github.com/[my-github-username]/zip5/fork )
|
60
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/zip5.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "zip5/version"
|
2
|
+
|
3
|
+
module Zip5
|
4
|
+
VALID = 501..99950
|
5
|
+
|
6
|
+
def Zip5.zip5(input)
|
7
|
+
input = input.to_i.to_s.delete('-')
|
8
|
+
memo = case input.length
|
9
|
+
when 9
|
10
|
+
input[0,5]
|
11
|
+
when 8
|
12
|
+
'0' + input[0,4]
|
13
|
+
when 7
|
14
|
+
'00' + input[0,3]
|
15
|
+
when 5
|
16
|
+
input
|
17
|
+
when 4
|
18
|
+
'0' + input
|
19
|
+
when 3
|
20
|
+
'00' + input
|
21
|
+
else
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
if ENV['VERBOSE'] == 'true' and not VALID.include?(memo.to_i)
|
25
|
+
$stderr.puts "warning: looks like a bad zip5 (expected 00500..99950): #{memo}"
|
26
|
+
end
|
27
|
+
memo
|
28
|
+
end
|
29
|
+
end
|
data/lib/zip5/version.rb
ADDED
data/spec/spec_helper.rb
ADDED
data/spec/zip5_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zip5 do
|
4
|
+
{
|
5
|
+
999501234 => '99950',
|
6
|
+
'99950-1234' => '99950',
|
7
|
+
57531234 => '05753',
|
8
|
+
'5753-1234' => '05753',
|
9
|
+
'05753-1234' => '05753',
|
10
|
+
5011234 => '00501',
|
11
|
+
99950 => '99950',
|
12
|
+
5753 => '05753',
|
13
|
+
1000 => '01000',
|
14
|
+
501 => '00501',
|
15
|
+
'' => nil,
|
16
|
+
'abc' => nil,
|
17
|
+
}.each do |input, expected|
|
18
|
+
it "parses #{input.inspect} as #{expected.inspect}" do
|
19
|
+
expect(Zip5.zip5(input)).to eq(expected)
|
20
|
+
end
|
21
|
+
# here we also test 57531234.0, etc.
|
22
|
+
if input.is_a?(Integer)
|
23
|
+
input_f = input.to_f
|
24
|
+
it "parses #{input_f.inspect} as #{expected.inspect}" do
|
25
|
+
expect(Zip5.zip5(input_f)).to eq(expected)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/zip5.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zip5/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zip5"
|
8
|
+
spec.version = Zip5::VERSION
|
9
|
+
spec.authors = ["Seamus Abshere"]
|
10
|
+
spec.email = ["seamus@abshere.net"]
|
11
|
+
spec.summary = %q{Convert United States zip codes to their correct Zip5 representation, even if they're missing a leading zero and/or they have the +4 suffix.}
|
12
|
+
spec.description = %q{For example, 8840 means 08840 and 5011234 means 00501-1234.}
|
13
|
+
spec.homepage = "https://github.com/seamusabshere/zip5"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zip5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seamus Abshere
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: For example, 8840 means 08840 and 5011234 means 00501-1234.
|
56
|
+
email:
|
57
|
+
- seamus@abshere.net
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/zip5.rb
|
70
|
+
- lib/zip5/version.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
- spec/zip5_spec.rb
|
73
|
+
- zip5.gemspec
|
74
|
+
homepage: https://github.com/seamusabshere/zip5
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Convert United States zip codes to their correct Zip5 representation, even
|
98
|
+
if they're missing a leading zero and/or they have the +4 suffix.
|
99
|
+
test_files:
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
- spec/zip5_spec.rb
|