From 4bb41db88238628e31dd9ec27971bfb3e995c55a Mon Sep 17 00:00:00 2001 From: Rob Murray <robmurray17@gmail.com> Date: Sat, 11 Oct 2014 08:48:47 +0100 Subject: [PATCH] return OS GridReference as explicit method rather than part of address --- lib/geocoder/results/postcode_anywhere_uk.rb | 6 +++++- test/unit/lookups/postcode_anywhere_uk_test.rb | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/geocoder/results/postcode_anywhere_uk.rb b/lib/geocoder/results/postcode_anywhere_uk.rb index 3f51fbba..0ebd65db 100644 --- a/lib/geocoder/results/postcode_anywhere_uk.rb +++ b/lib/geocoder/results/postcode_anywhere_uk.rb @@ -15,7 +15,7 @@ module Geocoder::Result alias_method :postal_code, :blank_result def address - [@data['Location'], @data['OsGrid']].join(', ') + @data['Location'] end def city @@ -25,6 +25,10 @@ module Geocoder::Result city.strip end + def os_grid + @data['OsGrid'] + end + # This is a UK only API; all results are UK specific and # so ommitted from API response. def country diff --git a/test/unit/lookups/postcode_anywhere_uk_test.rb b/test/unit/lookups/postcode_anywhere_uk_test.rb index 83f526ec..06000239 100644 --- a/test/unit/lookups/postcode_anywhere_uk_test.rb +++ b/test/unit/lookups/postcode_anywhere_uk_test.rb @@ -13,7 +13,8 @@ class PostcodeAnywhereUkTest < GeocoderTestCase results = Geocoder.search('Romsey') assert_equal 1, results.size - assert_equal 'Romsey, Hampshire, SU 35270 21182', results.first.address + assert_equal 'Romsey, Hampshire', results.first.address + assert_equal 'SU 35270 21182', results.first.os_grid assert_equal [50.9889, -1.4989], results.first.coordinates assert_equal 'Romsey', results.first.city end @@ -22,7 +23,8 @@ class PostcodeAnywhereUkTest < GeocoderTestCase results = Geocoder.search('WR26NJ') assert_equal 1, results.size - assert_equal 'Moseley Road, Hallow, Worcester, SO 81676 59425', results.first.address + assert_equal 'Moseley Road, Hallow, Worcester', results.first.address + assert_equal 'SO 81676 59425', results.first.os_grid assert_equal [52.2327, -2.2697], results.first.coordinates assert_equal 'Hallow', results.first.city end @@ -31,7 +33,8 @@ class PostcodeAnywhereUkTest < GeocoderTestCase results = Geocoder.search('hampshire') assert_equal 1, results.size - assert_equal 'Hampshire, SU 48701 26642', results.first.address + assert_equal 'Hampshire', results.first.address + assert_equal 'SU 48701 26642', results.first.os_grid assert_equal [51.037, -1.3068], results.first.coordinates assert_equal '', results.first.city end -- GitLab