zipcoder 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33e7e2b9eb15e35a4b1248e3a16772d6763880e7
4
- data.tar.gz: db823f8dccbfb1292b85be3bd2111e96f237f748
3
+ metadata.gz: 81f8212570017ee9537ad0ff17af68e6d4abec2d
4
+ data.tar.gz: c24abbd919537c6ebcc4d9f21f72abff19979613
5
5
  SHA512:
6
- metadata.gz: db14e8d94211f815d508eaaf375ffbe2dc5472a31c525597d3d1de9d3519f0a3b0e0502a44bd8467fa86603b6cabeab49dbea7bb1f647eed653dc62b6c584a59
7
- data.tar.gz: 672abf7c9f868cc4fe0083472e66b1ad3989155f1829bd04181db34985bdc3c7fa0b83f4c138a5bb8ef3160a8f52872f3f1d31968be0363c743cd1aaa2ba5ce0
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=92813c17f9c9510c4c644e41683e7ba2572e0b2a)](https://circleci.com/gh/ericchapman/zipcoder/tree/master)
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
- # > {:zips=>["73301", ...], :city=>"AUSTIN", :state=>"TX", :lats=>[30.26, ...], :longs=>[-97.74, ...]}
95
+ # > {:zip=>"78701-78799", :city=>"AUSTIN", :state=>"TX", :lat=>30.26, :long=>-97.74}
90
96
  ```
91
97
 
92
- The "zips", "lats", and "longs" are all arrays where each value is representing
93
- the info for a specific zip code.
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
- Note that the library will normalize the key by removing all of the whitespace
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: [:zips])
105
- # > {:zips=>["73301", ...]}
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 [here](http://federalgovernmentzipcodes.us/).
111
- To update the database, run the following at command line from the top directory
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, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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 release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
- zip_lookup = "lib/data/zip_lookup.yml"
68
- puts "Writing data to '#{zip_lookup}'"
69
- File.open(zip_lookup, 'w') {|file| file.write zip_lookup_data.to_yaml }
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