Module: Geokit::Cached::Geocodable
- Defined in:
- lib/geokit/cached/geocodable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cache_location! ⇒ Object
- #cache_locations? ⇒ Boolean
- #cached_location ⇒ Object
- #complete_address ⇒ Object
- #geocode_address_cached ⇒ Object
- #multi_geocoder ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 |
# File 'lib/geokit/cached/geocodable.rb', line 5 def self.included(base) base.class_eval do attr_accessor :provider end end |
Instance Method Details
#cache_location! ⇒ Object
36 37 38 |
# File 'lib/geokit/cached/geocodable.rb', line 36 def cache_location! cached_location.cache!(:lat => lat, :lng => lng, :provider => provider, :city => city) if cache_locations? end |
#cache_locations? ⇒ Boolean
28 29 30 |
# File 'lib/geokit/cached/geocodable.rb', line 28 def cache_locations? self.class::CACHE_LOCATIONS end |
#cached_location ⇒ Object
32 33 34 |
# File 'lib/geokit/cached/geocodable.rb', line 32 def cached_location CachedLocation.find_by_address(complete_address) || CachedLocation.new(:address => complete_address) end |
#complete_address ⇒ Object
19 20 21 |
# File 'lib/geokit/cached/geocodable.rb', line 19 def complete_address "%s, %s" % [address, country] end |
#geocode_address_cached ⇒ Object
23 24 25 26 |
# File 'lib/geokit/cached/geocodable.rb', line 23 def geocode_address_cached @geo = multi_geocoder.geocode(complete_address) self.lat, self.lng, self.provider, self.city = @geo.lat, @geo.lng, @geo.provider, @geo.city if @geo.success end |
#multi_geocoder ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/geokit/cached/geocodable.rb', line 11 def multi_geocoder if cache_locations? Geokit::Geocoders::CachedMultiGeocoder else Geokit::Geocoders::MultiGeocoder end end |