Permalink
Browse files

Add street accessors to Google result

  • Loading branch information...
1 parent 6bd4b59 commit 84fe70e5a3fd1d8540ca268d8fcbfcdacd26668e @danielcnorman danielcnorman committed Jan 8, 2013
Showing with 21 additions and 0 deletions.
  1. +10 −0 lib/geocoder/results/google.rb
  2. +11 −0 test/services_test.rb
@@ -59,6 +59,16 @@ def route
end
end
+ def street_number
+ if street_number = address_components_of_type(:street_number).first
+ street_number['long_name']
+ end
+ end
+
+ def street_address
+ [street_number, route].compact.join(' ')
+ end
+
def types
@data['types']
end
View
@@ -17,6 +17,12 @@ def test_google_result_components_contains_route
result.address_components_of_type(:route).first['long_name']
end
+ def test_google_result_components_contains_street_number
+ result = Geocoder.search("Madison Square Garden, New York, NY").first
+ assert_equal "4",
+ result.address_components_of_type(:street_number).first['long_name']
+ end
+
def test_google_returns_city_when_no_locality_in_result
result = Geocoder.search("no locality").first
assert_equal "Haram", result.city
@@ -27,6 +33,11 @@ def test_google_city_results_returns_nil_if_no_matching_component_types
assert_equal nil, result.city
end
+ def test_google_street_address_returns_formatted_street_address
+ result = Geocoder.search("Madison Square Garden, New York, NY").first
+ assert_equal "4 Penn Plaza", result.street_address
+ end
+
def test_google_precision
result = Geocoder.search("Madison Square Garden, New York, NY").first
assert_equal "ROOFTOP",

0 comments on commit 84fe70e

Please sign in to comment.