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" ...@@ -3,43 +3,42 @@ require "geocoder/results/nominatim"
module Geocoder::Lookup module Geocoder::Lookup
class Nominatim < Base class Nominatim < Base
def map_link_url(coordinates) def map_link_url(coordinates)
"http://nominatim.openstreetmap.org/reverse?format=html&lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=18&addressdetails=1" "http://nominatim.openstreetmap.org/reverse?format=html&lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=18&addressdetails=1"
end end
def results(query, reverse = false) def results(query, reverse = false)
return [] unless doc = fetch_data(query, reverse) return [] unless doc = fetch_data(query, reverse)
if doc.kind_of?(Array) if doc.kind_of?(Array)
if doc.any? if doc.any?
return doc[0]['place_id'] != "" ? doc : [] return doc[0]['place_id'] != "" ? doc : []
else else
warn "Address not found or Nominatim Geocoding API error." warn "Address not found or Nominatim Geocoding API error."
return [] return []
end end
else else
return doc['place_id'] != "" ? doc = [] << doc : [] return doc['place_id'] != "" ? doc = [] << doc : []
end end
end end
def query_url(query, reverse = false) def query_url(query, reverse = false)
params = { params = {
:format => "json", :format => "json",
:polygon => "1", :polygon => "1",
:addressdetails => "1", :addressdetails => "1",
# :locale => "#{Geocoder::Configuration.language}_US", #:locale => "#{Geocoder::Configuration.language}_US",
} }
if (reverse) if (reverse)
method = 'reverse' method = 'reverse'
parts = query.split(/\s*,\s*/); parts = query.split(/\s*,\s*/);
params[:lat] = parts[0] params[:lat] = parts[0]
params[:lon] = parts[1] params[:lon] = parts[1]
else else
method = 'search' method = 'search'
params[:q] = query params[:q] = query
end end
"http://nominatim.openstreetmap.org/#{method}?" + hash_to_query(params) "http://nominatim.openstreetmap.org/#{method}?" + hash_to_query(params)
end end
end end
end end
\ No newline at end of file
...@@ -2,30 +2,30 @@ require 'geocoder/results/base' ...@@ -2,30 +2,30 @@ require 'geocoder/results/base'
module Geocoder::Result module Geocoder::Result
class Nominatim < Base class Nominatim < Base
def house_number def house_number
@data['address']['house_number'] @data['address']['house_number']
end end
def address def address
@data['display_name'] @data['display_name']
end end
def street def street
@data['address']['road'] @data['address']['road']
end end
def city def city
@data['address']['city'] @data['address']['city']
end
def village
@data['address']['villiage']
end
def town
@data['address']['town']
end end
def village
@data['address']['villiage']
end
def town
@data['address']['town']
end
def state def state
@data['address']['state'] @data['address']['state']
...@@ -33,13 +33,13 @@ module Geocoder::Result ...@@ -33,13 +33,13 @@ module Geocoder::Result
alias_method :state_code, :state alias_method :state_code, :state
def postal_code def postal_code
@data['address']['postcode'] @data['address']['postcode']
end end
def county def county
@data['address']['county'] @data['address']['county']
end end
def country def country
@data['address']['country'] @data['address']['country']
...@@ -48,21 +48,20 @@ module Geocoder::Result ...@@ -48,21 +48,20 @@ module Geocoder::Result
def country_code def country_code
@data['address']['country_code'] @data['address']['country_code']
end end
def coordinates 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 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| response_attributes.each do |a|
define_method a do define_method a do
@data[a] @data[a]
end end
end end
end
end end
end
\ No newline at end of file
...@@ -110,9 +110,9 @@ class ServicesTest < Test::Unit::TestCase ...@@ -110,9 +110,9 @@ class ServicesTest < Test::Unit::TestCase
results = Geocoder.search("no results") results = Geocoder.search("no results")
assert_equal 0, results.length assert_equal 0, results.length
end end
# --- Nominatim --- # --- Nominatim ---
def test_nominatim_result_components def test_nominatim_result_components
Geocoder::Configuration.lookup = :nominatim Geocoder::Configuration.lookup = :nominatim
result = Geocoder.search("Madison Square Garden, New York, NY").first result = Geocoder.search("Madison Square Garden, New York, NY").first
...@@ -125,7 +125,4 @@ class ServicesTest < Test::Unit::TestCase ...@@ -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", assert_equal "Madison Square Garden, West 31st Street, Long Island City, New York City, New York, 10001, United States of America",
result.address result.address
end end
end end
...@@ -150,7 +150,7 @@ module Geocoder ...@@ -150,7 +150,7 @@ module Geocoder
end end
end end
class Nominatim < Base class Nominatim < Base
private #----------------------------------------------------------------- private #-----------------------------------------------------------------
def fetch_raw_data(query, reverse = false) def fetch_raw_data(query, reverse = false)
raise TimeoutError if query == "timeout" 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