zipcoder 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -12
- data/Rakefile +5 -24
- data/lib/data/{zip_lookup.yml → zip_data.yml} +135 -75441
- data/lib/ext/integer.rb +5 -2
- data/lib/ext/string.rb +5 -22
- data/lib/zipcoder/version.rb +1 -1
- data/lib/zipcoder.rb +118 -12
- data/spec/zipcoder_spec.rb +112 -10
- metadata +3 -4
- data/lib/data/city_lookup.yml +0 -306283
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81f8212570017ee9537ad0ff17af68e6d4abec2d
|
4
|
+
data.tar.gz: c24abbd919537c6ebcc4d9f21f72abff19979613
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6c6b76529f9741f02b1e46c743452b496483d72b89e2c4d0cb164646aa5764d6fd2ed3e9e63760cfc12f98606bc96066fb66ea50be1a12b5c3ca8906301b069
|
7
|
+
data.tar.gz: 16f706497a1007b065a70aa50bcc08c3b94c7934da54f682601751065b8ce47727922a993089d11d7273f1e534e82eb0c861787f24b6131a2be73ea5006661e3
|
data/README.md
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
# Zipcoder
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/zipcoder.svg)](https://badge.fury.io/rb/zipcoder)
|
3
|
-
[![Circle CI](https://circleci.com/gh/ericchapman/zipcoder/tree/master.svg?&style=shield&circle-token=
|
3
|
+
[![Circle CI](https://circleci.com/gh/ericchapman/zipcoder/tree/master.svg?&style=shield&circle-token=a6120adc7b90f211b8c19b16e184da4123de671c)](https://circleci.com/gh/ericchapman/zipcoder/tree/master)
|
4
4
|
[![Codecov](https://img.shields.io/codecov/c/github/ericchapman/zipcoder/master.svg)](https://codecov.io/github/ericchapman/zipcoder)
|
5
5
|
|
6
6
|
Gem for performing zip code lookup operations
|
7
7
|
|
8
8
|
## Revision History
|
9
9
|
|
10
|
+
- v0.2.0:
|
11
|
+
- Internal code rework
|
12
|
+
- API Change!! - changed "city,state" to return normalized info rather
|
13
|
+
than array of zips, lats, longs
|
10
14
|
- v0.1.0:
|
11
15
|
- Initial Revision
|
12
16
|
|
@@ -68,6 +72,8 @@ puts 78748.zip_info
|
|
68
72
|
# > {:zip=>"78748", :city=>"AUSTIN", :state=>"TX", :lat=>30.26, :long=>-97.74}
|
69
73
|
```
|
70
74
|
|
75
|
+
##### "keys" argument
|
76
|
+
|
71
77
|
You can filter the keys that are returned by including the "keys" argument
|
72
78
|
as shown below
|
73
79
|
|
@@ -86,14 +92,20 @@ This will return info about a city
|
|
86
92
|
require 'zipcoder'
|
87
93
|
|
88
94
|
puts "Austin, TX".city_info
|
89
|
-
# > {:
|
95
|
+
# > {:zip=>"78701-78799", :city=>"AUSTIN", :state=>"TX", :lat=>30.26, :long=>-97.74}
|
90
96
|
```
|
91
97
|
|
92
|
-
|
93
|
-
|
98
|
+
Notes:
|
99
|
+
|
100
|
+
- the "zip", "lat", "long" are the combined values from all of the
|
101
|
+
individual zip codes
|
102
|
+
- the library will normalize the key by removing all of the whitespace
|
103
|
+
and capitalizing the letters. So for example, "Austin, TX" becomes
|
104
|
+
"AUSTIN,TX"
|
105
|
+
- the library will cache the normalized cities to improve performance
|
106
|
+
on subsequent calls
|
94
107
|
|
95
|
-
|
96
|
-
and capitalizing the letters. So for example, "Austin, TX" becomes "AUSTIN,TX".
|
108
|
+
##### "keys" argument
|
97
109
|
|
98
110
|
You can filter the keys that are returned by including the "keys" argument
|
99
111
|
as shown below
|
@@ -101,14 +113,15 @@ as shown below
|
|
101
113
|
``` ruby
|
102
114
|
require 'zipcoder'
|
103
115
|
|
104
|
-
puts "Austin, TX".city_info(keys: [:
|
105
|
-
# > {:
|
116
|
+
puts "Austin, TX".city_info(keys: [:zip])
|
117
|
+
# > {:zip=>"78701-78799"}
|
106
118
|
```
|
107
119
|
|
108
120
|
### Updating Data
|
109
121
|
|
110
|
-
The library is using the free public zip code data base located
|
111
|
-
To update the database, run the
|
122
|
+
The library is using the free public zip code data base located
|
123
|
+
[here](http://federalgovernmentzipcodes.us/). To update the database, run the
|
124
|
+
following at command line from the top directory
|
112
125
|
|
113
126
|
```
|
114
127
|
%> rake zipcoder:update # Pulls the latest CSV file from the website
|
@@ -117,9 +130,14 @@ To update the database, run the following at command line from the top directory
|
|
117
130
|
|
118
131
|
## Development
|
119
132
|
|
120
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
133
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
134
|
+
run `rake spec` to run the tests. You can also run `bin/console` for an interactive
|
135
|
+
prompt that will allow you to experiment.
|
121
136
|
|
122
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
137
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
138
|
+
release a new version, update the version number in `version.rb`, and then run
|
139
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
140
|
+
git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
123
141
|
|
124
142
|
## Contributing
|
125
143
|
|
data/Rakefile
CHANGED
@@ -38,6 +38,8 @@ namespace :zipcoder do
|
|
38
38
|
csv = CSV.parse(csv_text, :headers => true)
|
39
39
|
puts "Importing data from '#{filename}'"
|
40
40
|
csv.each do |row|
|
41
|
+
next if row["ZipCodeType"] != "STANDARD"
|
42
|
+
|
41
43
|
zip_code = row["Zipcode"]
|
42
44
|
city = row["City"]
|
43
45
|
state = row["State"]
|
@@ -46,32 +48,11 @@ namespace :zipcoder do
|
|
46
48
|
|
47
49
|
# Write the zip_lookup_data
|
48
50
|
zip_lookup_data[zip_code] = { zip: zip_code, city: city, state: state, lat: lat, long: long }
|
49
|
-
|
50
|
-
# Write the city_lookup_data
|
51
|
-
city_key = "#{city},#{state}"
|
52
|
-
city_data = city_lookup_data[city_key] || {}
|
53
|
-
|
54
|
-
zips = city_data[:zips] || []
|
55
|
-
zips << zip_code
|
56
|
-
|
57
|
-
lats = city_data[:lats] || []
|
58
|
-
lats << lat
|
59
|
-
|
60
|
-
longs = city_data[:longs] || []
|
61
|
-
longs << long
|
62
|
-
|
63
|
-
city_lookup_data[city_key] = { zips: zips, city: city, state: state, lats: lats, longs: longs }
|
64
51
|
end
|
65
52
|
|
66
53
|
# Write the data to the yaml file
|
67
|
-
|
68
|
-
puts "Writing data to '#{
|
69
|
-
File.open(
|
70
|
-
|
71
|
-
# Write the city lookup data
|
72
|
-
city_lookup = "lib/data/city_lookup.yml"
|
73
|
-
puts "Writing data to '#{city_lookup}'"
|
74
|
-
File.open(city_lookup, 'w') {|file| file.write city_lookup_data.to_yaml }
|
75
|
-
|
54
|
+
zip_data = "lib/data/zip_data.yml"
|
55
|
+
puts "Writing data to '#{zip_data}'"
|
56
|
+
File.open(zip_data, 'w') {|file| file.write zip_lookup_data.to_yaml }
|
76
57
|
end
|
77
58
|
end
|