From 963ba724e2c20911ec624f8823297acc56d43d9a Mon Sep 17 00:00:00 2001
From: Rob Murray <robmurray17@gmail.com>
Date: Wed, 21 May 2014 17:36:18 +0100
Subject: [PATCH] It appears that we have to implement the 'city' method on the
 'Results' object too

---
 lib/geocoder/results/postcode_anywhere_uk.rb   | 17 ++++++++++++-----
 test/unit/lookups/postcode_anywhere_uk_test.rb | 12 ++++++------
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/lib/geocoder/results/postcode_anywhere_uk.rb b/lib/geocoder/results/postcode_anywhere_uk.rb
index b3194959..9b402d8d 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 77c481d5..c9ce9360 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
-- 
GitLab