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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59d5ba25d495af3bad83e0bcaadbf2339f4c9020
4
- data.tar.gz: 0f0e148e36a31e670d27291535f64137b076b115
3
+ metadata.gz: a2ac7c61de718237484499836acfc03035a9a6b9
4
+ data.tar.gz: d1bbbe88306a0266b7e5a5480179ccdf9eb381ae
5
5
  SHA512:
6
- metadata.gz: 32ae61b78e18a6cf2813de3a722544ed9cddd416bd85049c1b623d4051f837ceb0ecda6d8f48c87a89a879abd4adbafb285410a68d55457be97cd6ba94b85539
7
- data.tar.gz: 556ce818b6d646442ea0d7b8c4ff2a5d01a0fd9f49ecabd9d275b4117d58529eb8d1090ad62c9dc50973f3182425186fc8e524ea605815b32b9655dc3096e24f
6
+ metadata.gz: 7ff199f33606fd8d013457d4e1d5bdae4cd116ff5cbe7377c77ff6ba87ddfa2fe73ae468461db705cc7aa14bfa6cd39154ce9a7cd375e0322aabd5d1b7b2b7ae
7
+ data.tar.gz: 658e80c3e306be79c2300d43de0e3613eaa7f545e81c0b374f21e4c3d743bcae92ea0f87ddacaff5b0300d4b528a96d672604b6dad6d0bb79163eda122c4995a
data/.gitignore CHANGED
@@ -4,3 +4,5 @@
4
4
  /pkg/
5
5
  /vendor/cache/*.gem
6
6
  .rspec
7
+ Gemfile.lock
8
+ *.gem
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
- ZF ||= ZipFips::Handler.new
14
+ 12345.to_fips #=> 36093
15
+ 36093.to_zip #=> 12345
15
16
 
16
- ZF.to_fips(12345) #=> 36093
17
- ZF.to_zip(36093) #=> 12345
18
-
19
- ZF.convert(36093) #=> 12345
17
+ 36093.zipfips #=> 12345
20
18
 
21
19
  ## Install
22
20
 
@@ -1,3 +1,3 @@
1
1
  module ZipFips
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/zipfips.rb CHANGED
@@ -1,2 +1,46 @@
1
- require 'zipfips/version'
2
- require 'zipfips/handler'
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
- before do
5
- ZF ||= ZipFips::Handler.new
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(ZF.to_fips(12345)).to eq(36093)
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(ZF.to_zip(36093)).to eq(12345)
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(ZF.convert(36093)).to eq(12345)
18
- expect(ZF.convert(12345)).to eq(36093)
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.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-10-27 00:00:00.000000000 Z
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
@@ -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