Fork Of

Revisions

gist: 188709 Download_button fork
public
Public Clone URL: git://gist.github.com/188709.git
Embed All Files: show embed
fake_geocoder.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module GeoKit
  module Geocoders
    class FakeGeocoder < Geocoder
      def self.locations
        @locations ||= {}
      end
 
      def self.geocode(location)
        loc = GeoLoc.new
        if locations.key?(location)
          loc.lat, loc.lng = *locations.fetch(location)
          loc.success = true
        end
        loc
      end
 
      def self.[](key)
        locations[key]
      end
 
      def self.[]=(key, value)
        locations[key] = value
      end
 
      def self.clear
        locations.clear
      end
 
      def self.add_location_away_from(origin, options)
        bounds = GeoKit::Bounds.from_point_and_radius(origin, options[:distance])
        locations.store(options[:location], [bounds.sw.lat, bounds.center.lng])
      end
    end
  end
end