Skip to content
Snippets Groups Projects
Commit 2c63b645 authored by Alex Reisner's avatar Alex Reisner
Browse files

Clean up whitespace.

For consistency with rest of code.
parent 5b36a682
No related branches found
No related tags found
No related merge requests found
......@@ -3,43 +3,42 @@ require "geocoder/results/nominatim"
module Geocoder::Lookup
class Nominatim < Base
def map_link_url(coordinates)
"http://nominatim.openstreetmap.org/reverse?format=html&lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=18&addressdetails=1"
end
def results(query, reverse = false)
return [] unless doc = fetch_data(query, reverse)
if doc.kind_of?(Array)
if doc.any?
return doc[0]['place_id'] != "" ? doc : []
else
warn "Address not found or Nominatim Geocoding API error."
return []
end
else
return doc['place_id'] != "" ? doc = [] << doc : []
end
if doc.kind_of?(Array)
if doc.any?
return doc[0]['place_id'] != "" ? doc : []
else
warn "Address not found or Nominatim Geocoding API error."
return []
end
else
return doc['place_id'] != "" ? doc = [] << doc : []
end
end
def query_url(query, reverse = false)
params = {
:format => "json",
:polygon => "1",
:polygon => "1",
:addressdetails => "1",
# :locale => "#{Geocoder::Configuration.language}_US",
#:locale => "#{Geocoder::Configuration.language}_US",
}
if (reverse)
method = 'reverse'
parts = query.split(/\s*,\s*/);
params[:lat] = parts[0]
params[:lon] = parts[1]
else
method = 'search'
params[:q] = query
end
if (reverse)
method = 'reverse'
parts = query.split(/\s*,\s*/);
params[:lat] = parts[0]
params[:lon] = parts[1]
else
method = 'search'
params[:q] = query
end
"http://nominatim.openstreetmap.org/#{method}?" + hash_to_query(params)
end
end
end
end
\ No newline at end of file
end
......@@ -2,30 +2,30 @@ require 'geocoder/results/base'
module Geocoder::Result
class Nominatim < Base
def house_number
@data['address']['house_number']
end
def address
@data['display_name']
end
@data['address']['house_number']
end
def address
@data['display_name']
end
def street
@data['address']['road']
end
def city
@data['address']['city']
@data['address']['road']
end
def city
@data['address']['city']
end
def village
@data['address']['villiage']
end
def town
@data['address']['town']
end
def village
@data['address']['villiage']
end
def town
@data['address']['town']
end
def state
@data['address']['state']
......@@ -33,13 +33,13 @@ module Geocoder::Result
alias_method :state_code, :state
def postal_code
@data['address']['postcode']
end
def county
@data['address']['county']
end
def postal_code
@data['address']['postcode']
end
def county
@data['address']['county']
end
def country
@data['address']['country']
......@@ -48,21 +48,20 @@ module Geocoder::Result
def country_code
@data['address']['country_code']
end
def coordinates
[@data['lat'].to_f, @data['lon'].to_f]
[@data['lat'].to_f, @data['lon'].to_f]
end
def self.response_attributes
%w[place_id, osm_type, osm_id, boundingbox, license,
polygonpoints, display_name, class, type, stadium, suburb]
end
def self.response_attributes
%w[place_id, osm_type, osm_id, boundingbox, license,
polygonpoints, display_name, class, type, stadium, suburb]
end
response_attributes.each do |a|
define_method a do
@data[a]
end
end
end
end
\ No newline at end of file
end
end
end
......@@ -110,9 +110,9 @@ class ServicesTest < Test::Unit::TestCase
results = Geocoder.search("no results")
assert_equal 0, results.length
end
# --- Nominatim ---
def test_nominatim_result_components
Geocoder::Configuration.lookup = :nominatim
result = Geocoder.search("Madison Square Garden, New York, NY").first
......@@ -125,7 +125,4 @@ class ServicesTest < Test::Unit::TestCase
assert_equal "Madison Square Garden, West 31st Street, Long Island City, New York City, New York, 10001, United States of America",
result.address
end
end
......@@ -150,7 +150,7 @@ module Geocoder
end
end
class Nominatim < Base
class Nominatim < Base
private #-----------------------------------------------------------------
def fetch_raw_data(query, reverse = false)
raise TimeoutError if query == "timeout"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment