From 002121ed4f7d4d2a203cdbff2486799ea3ff04dc Mon Sep 17 00:00:00 2001
From: Yuri Veremeyenko <yuri.veremeyenko@gmail.com>
Date: Wed, 28 Jun 2017 20:29:12 +0200
Subject: [PATCH] add #city_district, #state_district, #neighbourhood to
 Geocoder::Result::Nominatim (#1194)

---
 lib/geocoder/results/nominatim.rb             | 12 +++++++
 ...ominatim_cologne_cathedral_cologne_germany | 36 +++++++++++++++++++
 test/unit/lookups/nominatim_test.rb           | 14 ++++++++
 3 files changed, 62 insertions(+)
 create mode 100644 test/fixtures/nominatim_cologne_cathedral_cologne_germany

diff --git a/lib/geocoder/results/nominatim.rb b/lib/geocoder/results/nominatim.rb
index d60005bd..c9934253 100644
--- a/lib/geocoder/results/nominatim.rb
+++ b/lib/geocoder/results/nominatim.rb
@@ -64,6 +64,18 @@ module Geocoder::Result
       @data['address']['suburb']
     end
 
+    def city_district
+      @data['address']['city_district']
+    end
+
+    def state_district
+      @data['address']['state_district']
+    end
+
+    def neighbourhood
+      @data['address']['neighbourhood']
+    end
+
     def coordinates
       [@data['lat'].to_f, @data['lon'].to_f]
     end
diff --git a/test/fixtures/nominatim_cologne_cathedral_cologne_germany b/test/fixtures/nominatim_cologne_cathedral_cologne_germany
new file mode 100644
index 00000000..5c7b774e
--- /dev/null
+++ b/test/fixtures/nominatim_cologne_cathedral_cologne_germany
@@ -0,0 +1,36 @@
+[
+  {
+    "place_id": "61478831",
+    "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright",
+    "osm_type": "way",
+    "osm_id": "4532022",
+    "boundingbox": [
+      "50.9409217",
+      "50.9417618",
+      "6.9570708",
+      "6.9591382"
+    ],
+    "lat": "50.94134445",
+    "lon": "6.95812085888689",
+    "display_name": "Cologne Cathedral, 4, Domkloster, Kunibertsviertel, Altstadt-Nord, Innenstadt, Cologne, Cologne Government Region, North Rhine-Westphalia, 50667, Germany",
+    "class": "amenity",
+    "type": "place_of_worship",
+    "importance": 0.70253720393793,
+    "icon": "http://nominatim.openstreetmap.org/images/mapicons/place_of_worship_unknown3.p.20.png",
+    "address": {
+      "place_of_worship": "Cologne Cathedral",
+      "house_number": "4",
+      "pedestrian": "Domkloster",
+      "neighbourhood": "Kunibertsviertel",
+      "suburb": "Altstadt-Nord",
+      "city_district": "Innenstadt",
+      "city": "Cologne",
+      "county": "Cologne",
+      "state_district": "Cologne Government Region",
+      "state": "North Rhine-Westphalia",
+      "postcode": "50667",
+      "country": "Germany",
+      "country_code": "de"
+    }
+  }
+]
\ No newline at end of file
diff --git a/test/unit/lookups/nominatim_test.rb b/test/unit/lookups/nominatim_test.rb
index 9a56f483..27d2d1d7 100644
--- a/test/unit/lookups/nominatim_test.rb
+++ b/test/unit/lookups/nominatim_test.rb
@@ -11,6 +11,9 @@ class NominatimTest < GeocoderTestCase
   def test_result_components
     result = Geocoder.search("Madison Square Garden, New York, NY").first
     assert_equal "10001", result.postal_code
+    assert_nil result.city_district
+    assert_nil result.state_district
+    assert_nil result.neighbourhood
     assert_equal "Madison Square Garden, West 31st Street, Long Island City, New York City, New York, 10001, United States of America", result.address
   end
 
@@ -20,6 +23,17 @@ class NominatimTest < GeocoderTestCase
       result.viewport
   end
 
+  def test_city_state_district
+    result = Geocoder.search("cologne cathedral cologne germany").first
+    assert_equal "Innenstadt", result.city_district
+    assert_equal "Cologne Government Region", result.state_district
+  end
+
+  def test_neighbourhood
+    result = Geocoder.search("cologne cathedral cologne germany").first
+    assert_equal "Kunibertsviertel", result.neighbourhood
+  end
+
   def test_host_configuration
     Geocoder.configure(nominatim: {host: "local.com"})
     query = Geocoder::Query.new("Bluffton, SC")
-- 
GitLab