Skip to content

Commit

Permalink
[#29894063] Move Geocoder Google monkey patch.
Browse files Browse the repository at this point in the history
Move the monkey patchings of the Geocoder Google data result class out
to the /ext folder.
  • Loading branch information
cupakromer committed Jun 5, 2012
1 parent 0cfe7b4 commit 9cee101
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 38 deletions.
1 change: 1 addition & 0 deletions lib/fetcher/bing_maps_traffic.rb
@@ -1,4 +1,5 @@
require 'geocoder'
require 'geocoder/ext/result_google'

module Fetcher
class BingMapsTraffic < Base
Expand Down
39 changes: 1 addition & 38 deletions lib/fetcher/map_quest_traffic.rb
@@ -1,36 +1,5 @@
require 'geocoder'
require 'geocoder/results/google'

class Geocoder::Result::Google
BOUNDING_BOX_KEYS = [:north_lat, :east_lng, :south_lat, :west_lng].freeze

def bounding_box( order = BOUNDING_BOX_KEYS )
coordinates = map_box_keys_to_values
order.map{ |key| coordinates[key] }
end

private

def extract_bounding_box
bounds = geometry["bounds"]
[
bounds["northeast"]["lat"], # :north_lat
bounds["northeast"]["lng"], # :east_lng
bounds["southwest"]["lat"], # :south_lat
bounds["southwest"]["lng"], # :west_lng
]
end

# Map the BOUNDING_BOX_KEYS to the associated values
# Returns hash as:
# {
# north_lat: 39.0464399, east_lng: -76.9836289,
# south_lat: 38.995162, west_lng: -77.033157
# }
def map_box_keys_to_values
Hash[*BOUNDING_BOX_KEYS.zip(extract_bounding_box).flatten]
end
end
require 'geocoder/ext/result_google'

module Fetcher
class MapQuestTraffic < Base
Expand All @@ -39,8 +8,6 @@ class << self
attr_accessor :API_Key
end

LOCATION_URL = "http://www.mapquestapi.com/geocoding/v1"
ADDRESS_URI = "/address"
INCIDENTS_URI = "/incidents"

base_uri "http://www.mapquestapi.com/traffic/v1"
Expand All @@ -58,10 +25,6 @@ def find_zip_bounding_box
Geocoder.search(@cue)[0].bounding_box order
end

def address_options
as_query location: @cue
end

def traffic_options
as_query boundingBox: find_zip_bounding_box.join(','),
filters: :incidents,
Expand Down
32 changes: 32 additions & 0 deletions lib/geocoder/ext/result_google.rb
@@ -0,0 +1,32 @@
require 'geocoder/results/google'

class Geocoder::Result::Google
BOUNDING_BOX_KEYS = [:north_lat, :east_lng, :south_lat, :west_lng].freeze

def bounding_box( order = BOUNDING_BOX_KEYS )
coordinates = map_box_keys_to_values
order.map{ |key| coordinates[key] }
end

private

def extract_bounding_box
bounds = geometry["bounds"]
[
bounds["northeast"]["lat"], # :north_lat
bounds["northeast"]["lng"], # :east_lng
bounds["southwest"]["lat"], # :south_lat
bounds["southwest"]["lng"], # :west_lng
]
end

# Map the BOUNDING_BOX_KEYS to the associated values
# Returns hash as:
# {
# north_lat: 39.0464399, east_lng: -76.9836289,
# south_lat: 38.995162, west_lng: -77.033157
# }
def map_box_keys_to_values
Hash[*BOUNDING_BOX_KEYS.zip(extract_bounding_box).flatten]
end
end

0 comments on commit 9cee101

Please sign in to comment.