Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#29894063] Move Geocoder Google monkey patch.
Move the monkey patchings of the Geocoder Google data result class out to the /ext folder.
- Loading branch information
1 parent
0cfe7b4
commit 9cee101
Showing
3 changed files
with
34 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'geocoder' | ||
require 'geocoder/ext/result_google' | ||
|
||
module Fetcher | ||
class BingMapsTraffic < Base | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |