zip_search 0.1.3 → 0.2.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86153186a510fff5b6492564b57e835462a0ce55
|
4
|
+
data.tar.gz: 443cb172444ab807b2f6aa08b8bac6c9211fb67f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b428c3c95f714a116a215bd772ef1f4606da03c75ad2ceb1e7cb66ffbfc96af270364110e76e97886f62cc8e4297b35b38d36a7a139b8f1dd1063f09b30cc532
|
7
|
+
data.tar.gz: c6e27cea29a19843d3647dd00406462fdb04449e5a6679739d145f330b3eee9d27494992e6aaae04df92ed2952abb55afa0a7144094f2b1f7cc6542f90778ad6
|
@@ -23,18 +23,28 @@ module ZipSearch
|
|
23
23
|
pg_search_scope :search_by_zip, against: :zip
|
24
24
|
|
25
25
|
geocoded_by :to_sentence
|
26
|
-
|
26
|
+
reverse_geocoded_by :latitude, :longitude do |obj, results|
|
27
|
+
if geo = results.first
|
28
|
+
obj.street_address ||= obj.street_address
|
29
|
+
obj.zip ||= geo.postal_code
|
30
|
+
obj.county ||= geo.county if geo.respond_to? :county
|
31
|
+
obj.city ||= geo.city
|
32
|
+
obj.state ||= geo.state
|
33
|
+
end
|
34
|
+
end
|
35
|
+
after_validation :geocode, if: :should_geocode?
|
36
|
+
after_validation :reverse_geocode, if: :should_reverse_geocode?
|
27
37
|
|
28
38
|
validates_presence_of :zs_association_name
|
29
39
|
|
30
40
|
include ActsAsLocation::LocalInstanceMethods
|
31
41
|
end
|
32
42
|
|
33
|
-
def location_fields; %i( zip county city state ) end
|
43
|
+
def location_fields; %i( street_address zip county city state ) end
|
34
44
|
|
35
45
|
def params(extra_params=[])
|
36
46
|
extra_params + [ :zs_association_name, :title, :latitude, :longitude,
|
37
|
-
:zip, :county, :city, :state ]
|
47
|
+
:street_address, :zip, :county, :city, :state ]
|
38
48
|
end
|
39
49
|
|
40
50
|
def nested_params(extra_params=[])
|
@@ -47,12 +57,18 @@ module ZipSearch
|
|
47
57
|
def location_fields; self.class.location_fields end
|
48
58
|
def location; Hash[ location_fields.map{|lf| [ lf, send(lf) ] } ] end
|
49
59
|
def location_blank?; location.values.reject(&:blank?).empty? end
|
60
|
+
def location_missing_any?; location.values.select(&:blank?).any? end
|
50
61
|
|
51
62
|
def to_sentence
|
52
63
|
return 'Location unavailable' if location_blank?
|
53
64
|
location_fields.map{|lf| send(lf) }.reject(&:blank?).join(', ')
|
54
65
|
end
|
55
66
|
|
67
|
+
def has_coordinates?; !latitude.nil? && !longitude.nil? end
|
68
|
+
def coordinates; [latitude, longitude] end
|
69
|
+
|
70
|
+
def should_geocode?; !has_coordinates? && !location_blank? end
|
71
|
+
def should_reverse_geocode?; has_coordinates? && location_missing_any? end
|
56
72
|
|
57
73
|
end
|
58
74
|
|
data/lib/zip_search/version.rb
CHANGED
@@ -35,4 +35,11 @@ describe Traveler do
|
|
35
35
|
expect(new_traveler.current_location.to_sentence).to eq 'Location unavailable'
|
36
36
|
end
|
37
37
|
|
38
|
+
it 'gets address components from street_address' do
|
39
|
+
expect {
|
40
|
+
new_traveler.current_location.street_address = '4910 E Warren Ave'
|
41
|
+
new_traveler.save
|
42
|
+
}.to change { new_traveler.current_location.latitude }
|
43
|
+
end
|
44
|
+
|
38
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zip_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MacKinley Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -332,6 +332,7 @@ files:
|
|
332
332
|
- config/spring.rb
|
333
333
|
- db/migrate/20150914014727_create_zip_search_locations.rb
|
334
334
|
- db/migrate/20150920034901_add_zs_association_name_to_zip_search_locations.rb
|
335
|
+
- db/migrate/20151004201251_add_full_street_address_to_zip_search_locations.rb
|
335
336
|
- lib/generators/zip_search/install/install_generator.rb
|
336
337
|
- lib/tasks/zip_search_tasks.rake
|
337
338
|
- lib/zip_search.rb
|