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: d64a97c6aa16248413d951fc224f8c2942f5c6f6
4
- data.tar.gz: 719632834d827a784a02c0c45637927fdc8732fe
3
+ metadata.gz: 86153186a510fff5b6492564b57e835462a0ce55
4
+ data.tar.gz: 443cb172444ab807b2f6aa08b8bac6c9211fb67f
5
5
  SHA512:
6
- metadata.gz: 919f138dc4487765fe4403c83107b3b5697ea7dbe317e69097e6f1ebada5c8e1af658826641fcd8a137ca2336fc50a01cea18a551d31f5c1e4bfcca34a571b59
7
- data.tar.gz: f415c6e7703aada2125ba8f7994974a5fec358dfc16e3eb1ab6efa188e06bfce7799e6e26a612ec64f551bcbef3ee3a74eb94e5fa7b7c4779d21ede0429a7b1d
6
+ metadata.gz: b428c3c95f714a116a215bd772ef1f4606da03c75ad2ceb1e7cb66ffbfc96af270364110e76e97886f62cc8e4297b35b38d36a7a139b8f1dd1063f09b30cc532
7
+ data.tar.gz: c6e27cea29a19843d3647dd00406462fdb04449e5a6679739d145f330b3eee9d27494992e6aaae04df92ed2952abb55afa0a7144094f2b1f7cc6542f90778ad6
@@ -0,0 +1,5 @@
1
+ class AddFullStreetAddressToZipSearchLocations < ActiveRecord::Migration
2
+ def change
3
+ add_column :zip_search_locations, :street_address, :string
4
+ end
5
+ end
@@ -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
- after_validation :geocode
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
 
@@ -38,7 +38,6 @@ module ZipSearch
38
38
  response
39
39
  end
40
40
 
41
-
42
41
  def apply_location_filtering(target)
43
42
  return target unless params.key? :zs_location
44
43
  zl = Location.find_by(id: params[:zlid].to_i)
@@ -1,3 +1,3 @@
1
1
  module ZipSearch
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -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.1.3
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-09-23 00:00:00.000000000 Z
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