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

Refactor to reduce code duplication.

parent db6d269a
No related branches found
No related tags found
No related merge requests found
......@@ -20,8 +20,20 @@ module Geocoder
##
# A string in the given format.
#
# This default implementation dumbly follows the United States address
# format and will return incorrect results for most countries. Some APIs
# return properly formatted addresses and those should be funneled
# through this method.
#
def address(format = :full)
fail
if state_code.to_s != ""
s = ", #{state_code}"
elsif state.to_s != ""
s = ", #{state}"
else
s = ""
end
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '')
end
##
......
......@@ -7,11 +7,6 @@ module Geocoder::Result
['latitude', 'longitude'].map{ |coordinate_name| @data[coordinate_name] }
end
def address(format = :full)
s = state_code.to_s == "" ? "" : ", #{state_code}"
"#{city}#{s} #{zip_code}, #{country_name}".sub(/^[ ,]*/, "")
end
def city
@data['city']
end
......
......@@ -3,11 +3,6 @@ require 'geocoder/results/base'
module Geocoder::Result
class Freegeoip < Base
def address(format = :full)
s = state_code.to_s == "" ? "" : ", #{state_code}"
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
end
def city
@data['city']
end
......
......@@ -3,10 +3,6 @@ require 'geocoder/results/base'
module Geocoder
module Result
class Geoip2 < Base
def address(format = :full)
s = state.to_s == '' ? '' : ", #{state_code}"
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '')
end
def coordinates
%w[latitude longitude].map do |l|
......
......@@ -3,11 +3,6 @@ require 'geocoder/results/base'
module Geocoder::Result
class IpdataCo < Base
def address(format = :full)
s = state_code.to_s == "" ? "" : ", #{state_code}"
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
end
def city
@data['city']
end
......
......@@ -87,11 +87,6 @@ module Geocoder::Result
[data_hash[:latitude].to_f, data_hash[:longitude].to_f]
end
def address(format = :full)
s = state_code.to_s == "" ? "" : ", #{state_code}"
"#{city}#{s} #{postal_code}, #{country_code}".sub(/^[ ,]*/, "")
end
def city
data_hash[:city_name]
end
......
......@@ -3,11 +3,6 @@ require 'geocoder/results/base'
module Geocoder::Result
class MaxmindLocal < Base
def address(format = :full)
s = state.to_s == "" ? "" : ", #{state}"
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
end
def coordinates
[@data[:latitude], @data[:longitude]]
end
......
......@@ -3,11 +3,6 @@ require 'geocoder/results/base'
module Geocoder::Result
class Telize < Base
def address(format = :full)
s = state_code.to_s == "" ? "" : ", #{state_code}"
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
end
def city
@data['city']
end
......
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