zipfips 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +3 -5
- data/lib/zipfips/version.rb +1 -1
- data/lib/zipfips.rb +46 -2
- data/spec/zipfips_spec.rb +11 -7
- metadata +2 -3
- data/lib/zipfips/handler.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2ac7c61de718237484499836acfc03035a9a6b9
|
4
|
+
data.tar.gz: d1bbbe88306a0266b7e5a5480179ccdf9eb381ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ff199f33606fd8d013457d4e1d5bdae4cd116ff5cbe7377c77ff6ba87ddfa2fe73ae468461db705cc7aa14bfa6cd39154ce9a7cd375e0322aabd5d1b7b2b7ae
|
7
|
+
data.tar.gz: 658e80c3e306be79c2300d43de0e3613eaa7f545e81c0b374f21e4c3d743bcae92ea0f87ddacaff5b0300d4b528a96d672604b6dad6d0bb79163eda122c4995a
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -11,12 +11,10 @@ Easily convert between ZIP codes and FIPS codes
|
|
11
11
|
|
12
12
|
require 'zipfips'
|
13
13
|
|
14
|
-
|
14
|
+
12345.to_fips #=> 36093
|
15
|
+
36093.to_zip #=> 12345
|
15
16
|
|
16
|
-
|
17
|
-
ZF.to_zip(36093) #=> 12345
|
18
|
-
|
19
|
-
ZF.convert(36093) #=> 12345
|
17
|
+
36093.zipfips #=> 12345
|
20
18
|
|
21
19
|
## Install
|
22
20
|
|
data/lib/zipfips/version.rb
CHANGED
data/lib/zipfips.rb
CHANGED
@@ -1,2 +1,46 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module ZipFips
|
4
|
+
|
5
|
+
def is_zip?
|
6
|
+
!!fips_hash[self.to_s] && !is_fips?
|
7
|
+
end
|
8
|
+
|
9
|
+
def is_fips?
|
10
|
+
!!zips_hash[self.to_s]
|
11
|
+
end
|
12
|
+
|
13
|
+
def zipfips
|
14
|
+
is_zip? ? to_fips : to_zip
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_zip
|
18
|
+
zips_hash[self.to_s].to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_fips
|
22
|
+
fips_hash[self.to_s].to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def fips_hash
|
28
|
+
@@fips_hash ||= JSON.parse(fips_file.read)
|
29
|
+
end
|
30
|
+
|
31
|
+
def fips_file
|
32
|
+
File.open("#{File.dirname(__FILE__)}/zipfips/data/data.json", "r")
|
33
|
+
end
|
34
|
+
|
35
|
+
def zips_hash
|
36
|
+
fips_hash.invert
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Fixnum
|
41
|
+
include ::ZipFips
|
42
|
+
end
|
43
|
+
|
44
|
+
class Integer
|
45
|
+
include ::ZipFips
|
46
|
+
end
|
data/spec/zipfips_spec.rb
CHANGED
@@ -1,20 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ZipFips do
|
4
|
-
|
5
|
-
|
6
|
-
end
|
4
|
+
zip = 12345
|
5
|
+
fips = 36093
|
7
6
|
|
8
7
|
it "should return the proper FIPS code for a ZIP code" do
|
9
|
-
expect(
|
8
|
+
expect(zip.to_fips).to eq(fips)
|
10
9
|
end
|
11
10
|
|
12
11
|
it "should return the proper ZIP code for a FIPS code" do
|
13
|
-
expect(
|
12
|
+
expect(fips.to_zip).to eq(zip)
|
14
13
|
end
|
15
14
|
|
16
15
|
it "should automatically convert between the two" do
|
17
|
-
expect(
|
18
|
-
expect(
|
16
|
+
expect(fips.zipfips).to eq(zip)
|
17
|
+
expect(zip.zipfips).to eq(fips)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should work for strings or numbers" do
|
21
|
+
expect(zip.to_fips).to eq(fips)
|
22
|
+
expect(zip.to_s.to_fips).to eq(fips)
|
19
23
|
end
|
20
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zipfips
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryce Dorn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,7 +94,6 @@ files:
|
|
94
94
|
- Rakefile
|
95
95
|
- lib/zipfips.rb
|
96
96
|
- lib/zipfips/data/data.json
|
97
|
-
- lib/zipfips/handler.rb
|
98
97
|
- lib/zipfips/version.rb
|
99
98
|
- spec/spec_helper.rb
|
100
99
|
- spec/zipfips_spec.rb
|
data/lib/zipfips/handler.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module ZipFips
|
4
|
-
class Handler
|
5
|
-
def is_zip?(code)
|
6
|
-
!!fips_hash[code.to_s] && !is_fips?(code)
|
7
|
-
end
|
8
|
-
|
9
|
-
def is_fips?(code)
|
10
|
-
!!zips_hash[code.to_s]
|
11
|
-
end
|
12
|
-
|
13
|
-
def convert(code)
|
14
|
-
is_zip?(code) ? to_fips(code) : to_zip(code)
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_zip(code)
|
18
|
-
zips_hash[code.to_s].to_i
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_fips(code)
|
22
|
-
fips_hash[code.to_s].to_i
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def fips_hash
|
28
|
-
@fips_hash ||= JSON.parse(fips_file.read)
|
29
|
-
end
|
30
|
-
|
31
|
-
def fips_file
|
32
|
-
File.open("#{File.dirname(__FILE__)}/data/data.json", "r")
|
33
|
-
end
|
34
|
-
|
35
|
-
def zips_hash
|
36
|
-
@zips_hash ||= fips_hash.invert
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|