Skip to content

Commit

Permalink
Implement county for OpenCage
Browse files Browse the repository at this point in the history
  • Loading branch information
dsantosmerino committed Jan 22, 2020
1 parent 3690523 commit 5612dca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/geokit/geocoders/opencage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def self.set_address_components(address_data, loc)
loc.country = address_data['country']
loc.country_code = address_data['country_code'].upcase if address_data['country_code']
loc.state_name = address_data['state']
loc.county = address_data['county']
loc.city = address_data['city']
loc.city = address_data['county'] if loc.city.nil? && address_data['county']
loc.zip = address_data['postcode']
Expand Down
11 changes: 8 additions & 3 deletions test/test_opencage_geocoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_opencage_full_address
res = geocode(@opencage_full_loc, :opencage_full)

assert_equal 'California', res.state
assert_equal 'San Francisco City and County', res.county
assert_equal 'San Francisco', res.city
assert_array_in_delta [37.7921509, -122.394], res.to_a
assert res.is_us?
Expand All @@ -35,6 +36,7 @@ def test_opencage_city
res = geocode(@opencage_city_loc, :opencage_city)

assert_equal 'California', res.state
assert_equal 'San Francisco City and County', res.county
assert_equal 'San Francisco', res.city
assert_array_in_delta [37.7792768, -122.4192704], res.to_a
assert res.is_us?
Expand All @@ -55,12 +57,13 @@ def test_opencage_reverse

assert_equal 'Chamberí', res.neighborhood
assert_equal 'Madrid', res.city
assert_equal 'Área metropolitana de Madrid y Corredor del Henares', res.county
assert_equal 'Community of Madrid', res.state

assert_equal 'Spain', res.country
assert_equal true, res.success

assert_equal "Calle De Zurbano, Chamberí, Madrid, Community of Madrid, 28036, ES", res.full_address
assert_equal 'Calle De Zurbano, Chamberí, Madrid, Community of Madrid, 28036, ES', res.full_address
assert_equal 28_036, res.zip
assert_equal 'Calle De Zurbano', res.street_address
end
Expand All @@ -79,13 +82,15 @@ def test_opencage_reverse2
assert_equal 'Жабино Маало', res.neighborhood
assert_equal 'Prilep', res.city
assert_equal 'Pelagonia Region', res.state
assert_equal 'Municipality of Prilep', res.county
assert_equal 'Prilep', res.city

assert_equal 'Macedonia', res.country
assert_equal 10, res.precision
assert_equal true, res.success

assert_equal "Прилепски Бранители, Prilep, Pelagonia Region, MK", res.full_address
assert_equal "Прилепски Бранители", res.street_address
assert_equal 'Прилепски Бранители, Prilep, Pelagonia Region, MK', res.full_address
assert_equal 'Прилепски Бранители', res.street_address
end

# check if the results are in Spanish if &language=es
Expand Down

0 comments on commit 5612dca

Please sign in to comment.