diff --git a/lib/geocoder/results/postcode_anywhere_uk.rb b/lib/geocoder/results/postcode_anywhere_uk.rb index b3194959022f817788ca118f5e3a35708380192f..9b402d8d62ebdef718daba66d43eea60aaddf607 100644 --- a/lib/geocoder/results/postcode_anywhere_uk.rb +++ b/lib/geocoder/results/postcode_anywhere_uk.rb @@ -14,6 +14,17 @@ module Geocoder::Result alias_method :state_code, :blank_result alias_method :postal_code, :blank_result + def address + [@data['Location'], @data['OsGrid']].join(', ') + end + + def city + # is this too big a jump to assume that the API always + # returns a City, County as the last elements? + city = @data['Location'].split(',')[-2] + city.strip + end + def country 'United Kingdom' end @@ -21,9 +32,5 @@ module Geocoder::Result def country_code 'UK' end - - def address - [@data['Location'], @data['OsGrid']].join(', ') - end end -end \ No newline at end of file +end diff --git a/test/unit/lookups/postcode_anywhere_uk_test.rb b/test/unit/lookups/postcode_anywhere_uk_test.rb index 77c481d5e1dd4e83eacf73ee32b18b14ba4703cb..c9ce9360642439904566b117cf49c96c7fa3d408 100644 --- a/test/unit/lookups/postcode_anywhere_uk_test.rb +++ b/test/unit/lookups/postcode_anywhere_uk_test.rb @@ -13,18 +13,18 @@ class PostcodeAnywhereUkTest < GeocoderTestCase results = Geocoder.search('Madison Square Garden') assert_equal 1, results.size - result = results.first - assert_equal 'Maidstone, Kent, TQ 76153 55386', result.address - assert_equal [51.2703, 0.5238], result.coordinates + assert_equal 'Maidstone, Kent, TQ 76153 55386', results.first.address + assert_equal [51.2703, 0.5238], results.first.coordinates + assert_equal 'Maidstone', results.first.city end def test_WR26NJ results = Geocoder.search('WR26NJ') assert_equal 1, results.size - result = results.first - assert_equal 'Moseley Road, Hallow, Worcester, SO 81676 59425', result.address - assert_equal [52.2327, -2.2697], result.coordinates + assert_equal 'Moseley Road, Hallow, Worcester, SO 81676 59425', results.first.address + assert_equal [52.2327, -2.2697], results.first.coordinates + assert_equal 'Hallow', results.first.city end def test_no_results