campfire_logic 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/models/locale.rb +2 -10
- data/app/models/location.rb +18 -3
- data/app/models/location_import.rb +0 -1
- data/campfire_logic.gemspec +2 -2
- data/spec/models/locale_spec.rb +1 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.4
|
data/app/models/locale.rb
CHANGED
@@ -48,20 +48,12 @@ class Locale
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# Instance methods: Initialization ===============================================================
|
51
|
-
|
52
51
|
def post_process
|
53
|
-
|
54
|
-
|
55
|
-
self.save
|
52
|
+
set_kind
|
53
|
+
save
|
56
54
|
end
|
57
55
|
|
58
56
|
# Instance methods: Overrides ====================================================================
|
59
|
-
|
60
|
-
# Returns this locale's latitude/longitude, delegating to location as needed (to prevent duplicate/conflicting coordinates).
|
61
|
-
def coordinates
|
62
|
-
self.location ? self.location.coordinates : self[:coordinates]
|
63
|
-
end
|
64
|
-
|
65
57
|
def friendly_name
|
66
58
|
self.city? ? "#{self.name}, #{self.parent.name}" : self.name
|
67
59
|
end
|
data/app/models/location.rb
CHANGED
@@ -81,6 +81,12 @@ class Location
|
|
81
81
|
location.coordinates = [geo.longitude, geo.latitude]
|
82
82
|
end
|
83
83
|
|
84
|
+
def self.geocode
|
85
|
+
p "Total not-geocoded locations: #{Location.not_geocoded.count}"
|
86
|
+
Location.not_geocoded.each{ |l| l.validate_address_and_localize }
|
87
|
+
"Not-geocoded locations remaining: #{Location.not_geocoded.count}"
|
88
|
+
end
|
89
|
+
|
84
90
|
# Instance methods: Overrides ====================================================================
|
85
91
|
def address1=(value)
|
86
92
|
clear_geocoding if self.address1 != value
|
@@ -134,6 +140,13 @@ class Location
|
|
134
140
|
geocoder_result.blank? || self.send(attribute) == geocoder_result.send(GOOGLE_MAPS_GEOCODER_FIELDS_BY_LOCATION_FIELD[attribute])
|
135
141
|
end
|
136
142
|
|
143
|
+
def validate_address_and_localize
|
144
|
+
if self.geocode
|
145
|
+
self.validate_address!
|
146
|
+
self.localize
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
137
150
|
# Instance methods: Locales ======================================================================
|
138
151
|
|
139
152
|
def localize
|
@@ -184,17 +197,19 @@ class Location
|
|
184
197
|
_state = Locale.find_or_create_state_for(self)
|
185
198
|
|
186
199
|
# Find or create a city locale for this location
|
187
|
-
_city = _state.children.to_a.detect{ |c| c.name =~ /#{self.city}/i } || (
|
200
|
+
_city = _state.children.to_a.detect{ |c| c.name =~ /#{self.city}/i } || (_state.children.create(:name => self.city))
|
188
201
|
|
189
202
|
# Find or create a locale for this location
|
190
|
-
self.locale = _city.children.to_a.detect{ |c| c.name =~ /#{self.name}/i } || (
|
203
|
+
self.locale = _city.children.to_a.detect{ |c| c.name =~ /#{self.name}/i } || (_city.children.create(:name => self.name, :skip_geocoding => true))
|
204
|
+
self.locale.coordinates = coordinates
|
191
205
|
self.locale.save
|
192
206
|
end
|
193
207
|
|
194
208
|
# Updates the locale tree for this location.
|
195
209
|
def update_locales
|
196
210
|
# update location
|
197
|
-
self.locale.
|
211
|
+
self.locale.coordinates = coordinates
|
212
|
+
self.locale.name = name
|
198
213
|
self.locale.save
|
199
214
|
|
200
215
|
# does its city locale have other locations?
|
data/campfire_logic.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "campfire_logic"
|
8
|
-
s.version = "2.0.
|
8
|
+
s.version = "2.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Roderick Monje"]
|
12
|
-
s.date = "2012-02-
|
12
|
+
s.date = "2012-02-21"
|
13
13
|
s.description = "Users can browse locations by country, city, and state and search locations by string or zip code. Administrators can manage locations and the services they offer."
|
14
14
|
s.email = "rod@seologic.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/models/locale_spec.rb
CHANGED
@@ -11,8 +11,7 @@ describe Locale do
|
|
11
11
|
# Location.any_instance.stubs :geocode
|
12
12
|
# GeocoderGoogleResult.stubs(:new).returns stub('prospect park zoo', :city => 'Brooklyn', :country_long_name => 'United States', :country_short_name => 'US', :formatted_address => '450 Flatbush Avenue', :formatted_street_address => '450 Flatbush Avenue', :lat => 1, :lng => 1, :partial_match? => false, :postal_code => '11217', :state_long_name => 'New York', :state_short_name => 'NY')
|
13
13
|
location = Location.new :address1 => '25 Columbia Heights', :city => 'Brooklyn', :name => 'Prospect Park Zoo', :state => 'NY'
|
14
|
-
location.
|
15
|
-
location.localize
|
14
|
+
location.validate_address_and_localize
|
16
15
|
end
|
17
16
|
|
18
17
|
it 'can skip geocoding on creation' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: campfire_logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 4
|
10
|
+
version: 2.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Roderick Monje
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-02-
|
18
|
+
date: 2012-02-21 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: bson_ext
|