Skip to content
Snippets Groups Projects
Commit a33bbebe authored by Alex Reisner's avatar Alex Reisner
Browse files

Merge pull request #373 from everydayhero/dn_google_street_accessors

Add street accessors to Google result
parents 6bd4b594 84fe70e5
No related branches found
No related tags found
No related merge requests found
...@@ -59,6 +59,16 @@ module Geocoder::Result ...@@ -59,6 +59,16 @@ module Geocoder::Result
end end
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 def types
@data['types'] @data['types']
end end
......
...@@ -17,6 +17,12 @@ class ServicesTest < Test::Unit::TestCase ...@@ -17,6 +17,12 @@ class ServicesTest < Test::Unit::TestCase
result.address_components_of_type(:route).first['long_name'] result.address_components_of_type(:route).first['long_name']
end 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 def test_google_returns_city_when_no_locality_in_result
result = Geocoder.search("no locality").first result = Geocoder.search("no locality").first
assert_equal "Haram", result.city assert_equal "Haram", result.city
...@@ -27,6 +33,11 @@ class ServicesTest < Test::Unit::TestCase ...@@ -27,6 +33,11 @@ class ServicesTest < Test::Unit::TestCase
assert_equal nil, result.city assert_equal nil, result.city
end 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 def test_google_precision
result = Geocoder.search("Madison Square Garden, New York, NY").first result = Geocoder.search("Madison Square Garden, New York, NY").first
assert_equal "ROOFTOP", assert_equal "ROOFTOP",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment