zipcoder 0.7.4 → 0.8.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.
@@ -52,19 +52,23 @@ module Zipcoder
52
52
  state_lookup = {}
53
53
 
54
54
  # Add the zip codes to the cache
55
- zip_codes.each do |zip, info|
56
- city = _capitalize_all(info[:city])
57
- info[:city] = city
58
- state = info[:state]
59
-
60
- # Iterate through the zip codes and add them to the zip cache
61
- _write_cache _zip_cache(zip), info
62
-
63
- # Create the city lookups
64
- city_state = "#{city.upcase},#{state.upcase}"
65
- infos = city_states[city_state] || []
66
- infos << info
67
- city_states[city_state] = infos
55
+ zip_codes.each do |zip, cities|
56
+ cities.each do |info|
57
+ city = _capitalize_all(info[:city])
58
+ info[:city] = city
59
+ state = info[:state]
60
+
61
+ # For the zip codes, only store the primary
62
+ if info[:primary]
63
+ _write_cache _zip_cache(zip), info
64
+ end
65
+
66
+ # Create the city lookups
67
+ city_state = "#{city.upcase},#{state.upcase}"
68
+ infos = city_states[city_state] || []
69
+ infos << info
70
+ city_states[city_state] = infos
71
+ end
68
72
  end
69
73
 
70
74
  # Normalize each city and populate the state cache
@@ -156,11 +160,13 @@ module Zipcoder
156
160
 
157
161
  # Iterate through the info and get min/max of zip/lat/long
158
162
  infos.each do |info|
163
+ if info[:primary]
164
+ lat_min = info[:lat] if info[:lat] < lat_min
165
+ lat_max = info[:lat] if info[:lat] > lat_max
166
+ long_min = info[:long] if info[:long] < long_min
167
+ long_max = info[:long] if info[:long] > long_max
168
+ end
159
169
  zips << info[:zip]
160
- lat_min = info[:lat] if info[:lat] < lat_min
161
- lat_max = info[:lat] if info[:lat] > lat_max
162
- long_min = info[:long] if info[:long] < long_min
163
- long_max = info[:long] if info[:long] > long_max
164
170
  end
165
171
 
166
172
  # Create the normalized value
@@ -1,3 +1,3 @@
1
1
  module Zipcoder
2
- VERSION = "0.7.4"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -121,7 +121,7 @@ describe Zipcoder do
121
121
  describe "#state_cities" do
122
122
  it "returns the cities for a state" do
123
123
  cities = described_class.state_cities "TX"
124
- expect(cities.count).to eq(1170)
124
+ expect(cities.count).to eq(1586)
125
125
 
126
126
  city_info = cities[0]
127
127
  expect(city_info[:city]).to eq("Abbott")
@@ -132,7 +132,7 @@ describe Zipcoder do
132
132
  end
133
133
  it "returns the cities for a state filtered" do
134
134
  cities = described_class.state_cities "TX", keys: [:zip, :city]
135
- expect(cities.count).to eq(1170)
135
+ expect(cities.count).to eq(1586)
136
136
 
137
137
  city_info = cities[0]
138
138
  expect(city_info[:city]).to eq("Abbott")
@@ -143,7 +143,7 @@ describe Zipcoder do
143
143
  end
144
144
  it "returns the names of the cities" do
145
145
  cities = described_class.state_cities "TX", names_only: true
146
- expect(cities.count).to eq(1170)
146
+ expect(cities.count).to eq(1586)
147
147
 
148
148
  expect(cities[0]).to eq("Abbott")
149
149
  end
@@ -216,7 +216,7 @@ describe Zipcoder do
216
216
  zip_info = zip_cities["13601"]
217
217
  expect(zip_info[:city]).to eq("Watertown")
218
218
  expect(zip_info[:state]).to eq("NY")
219
- expect(zip_info[:zip]).to eq("13601,13603")
219
+ expect(zip_info[:zip]).to eq("13601-13603")
220
220
  expect(zip_info[:lat]).to eq(43.97)
221
221
  expect(zip_info[:long]).to eq(-75.91)
222
222
  end
@@ -282,6 +282,7 @@ describe Zipcoder do
282
282
  expect(city_info[:lat]).to eq(30.315)
283
283
  expect(city_info[:long]).to eq(-97.71)
284
284
  end
285
+
285
286
  it "only returns specified keys" do
286
287
  city_info = "Austin, TX".city_info keys: [:zip, :city]
287
288
  expect(city_info[:city]).to eq("Austin")
@@ -290,22 +291,33 @@ describe Zipcoder do
290
291
  expect(city_info[:lat]).to be_nil
291
292
  expect(city_info[:long]).to be_nil
292
293
  end
294
+
293
295
  it "only returns the zip codes" do
294
296
  zip_codes = "Austin, TX".city_info zips_only: true
295
297
  expect(zip_codes.count).to eq(47)
296
298
  expect(zip_codes[0]).to eq('78701')
297
299
  expect(zip_codes[-1]).to eq('78799')
298
300
  end
301
+
299
302
  it "returns an nil when the city state is non-existent" do
300
303
  zip_codes = ", ".city_info
301
304
  expect(zip_codes).to be_nil
302
305
  end
306
+
307
+ it "returns the info for an acceptable city" do
308
+ city_info = "West Lake Hills, TX".city_info
309
+ expect(city_info[:city]).to eq("West Lake Hills")
310
+ expect(city_info[:state]).to eq("TX")
311
+ expect(city_info[:zip]).to eq("78746")
312
+ expect(city_info[:lat]).to eq(30.26)
313
+ expect(city_info[:long]).to eq(-97.74)
314
+ end
303
315
  end
304
316
 
305
317
  describe "state_cities" do
306
318
  it "returns the cities for a state" do
307
319
  cities = "TX".state_cities
308
- expect(cities.count).to eq(1170)
320
+ expect(cities.count).to eq(1586)
309
321
 
310
322
  city_info = cities[0]
311
323
  expect(city_info[:city]).to eq("Abbott")
@@ -316,7 +328,7 @@ describe Zipcoder do
316
328
  end
317
329
  it "returns the cities for a state filtered" do
318
330
  cities = "TX".state_cities keys: [:zip, :city]
319
- expect(cities.count).to eq(1170)
331
+ expect(cities.count).to eq(1586)
320
332
 
321
333
  city_info = cities[0]
322
334
  expect(city_info[:city]).to eq("Abbott")
@@ -325,6 +337,18 @@ describe Zipcoder do
325
337
  expect(city_info[:lat]).to be_nil
326
338
  expect(city_info[:long]).to be_nil
327
339
  end
340
+
341
+ it "has secondary cities" do
342
+ contains_acceptable = false
343
+ "TX".state_cities.each do |info|
344
+ if info[:city] == "West Lake Hills"
345
+ contains_acceptable = true
346
+ break
347
+ end
348
+ end
349
+
350
+ expect(contains_acceptable).to eq(true)
351
+ end
328
352
  end
329
353
  end
330
354
 
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipcoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Chapman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-30 00:00:00.000000000 Z
11
+ date: 2018-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 3.5.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.5.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: codecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: redis
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 3.3.5
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 3.3.5
97
97
  description:
@@ -103,9 +103,9 @@ executables:
103
103
  extensions: []
104
104
  extra_rdoc_files: []
105
105
  files:
106
- - .gitignore
107
- - .rspec
108
- - .ruby-version
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".ruby-version"
109
109
  - Gemfile
110
110
  - LICENSE.txt
111
111
  - README.md
@@ -138,17 +138,17 @@ require_paths:
138
138
  - lib
139
139
  required_ruby_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
- - - '>='
141
+ - - ">="
142
142
  - !ruby/object:Gem::Version
143
143
  version: '2.0'
144
144
  required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  requirements:
146
- - - '>='
146
+ - - ">="
147
147
  - !ruby/object:Gem::Version
148
148
  version: '0'
149
149
  requirements: []
150
150
  rubyforge_project:
151
- rubygems_version: 2.4.8
151
+ rubygems_version: 2.5.1
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: Converts zip codes to cities, lat/long, and vice-versa