Module: Mappable
- Includes:
- Geokit::Geocoders
- Defined in:
- lib/mappable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #geocodable_columns ⇒ Object
- #geocode ⇒ Object
- #geocode_basis ⇒ Object
- #geocoded ⇒ Object
- #url ⇒ Object
Class Method Details
.included(base) ⇒ Object
6 7 8 9 10 |
# File 'lib/mappable.rb', line 6 def self.included(base) base.class_eval { before_validation :geocode_location } end |
Instance Method Details
#geocodable_columns ⇒ Object
24 25 26 |
# File 'lib/mappable.rb', line 24 def geocodable_columns [:postcode, :location, :address] end |
#geocode ⇒ Object
12 13 14 |
# File 'lib/mappable.rb', line 12 def geocode "#{lat},#{lng}" if geocoded end |
#geocode_basis ⇒ Object
20 21 22 |
# File 'lib/mappable.rb', line 20 def geocode_basis geocodable_columns.map{ |f| send(f) }.find{|v| !v.blank?} end |
#geocoded ⇒ Object
16 17 18 |
# File 'lib/mappable.rb', line 16 def geocoded true if lat && lng end |
#url ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mappable.rb', line 28 def url if url = read_attribute(:url) && !url.blank? url elsif geocoded format = Radiant::Config['event_map.link_format'] format = 'google' if format.blank? case format when 'bing' "http://www.bing.com/maps/?v=2&cp=#{lat}~#{lng}&rtp=~pos.#{lat}_#{lng}_#{title}&lvl=15&sty=s&eo=0" when 'google' "http://maps.google.com/maps?q=#{lat}+#{lng}+(#{title})" when String interpolations = %w{lat lng title} interpolations.inject( format.dup ) do |result, tag| result.gsub(/:#{tag}/) { send( tag ) } end end end end |