lib/geocoder/lookups/base.rb in geocoder-0.9.11 vs lib/geocoder/lookups/base.rb in geocoder-0.9.12

- old
+ new

@@ -18,13 +18,27 @@ # # Takes a search string (eg: "Mississippi Coast Coliseumf, Biloxi, MS", # "205.128.54.202") for geocoding, or coordinates (latitude, longitude) # for reverse geocoding. Returns an array of <tt>Geocoder::Result</tt>s. # - def search(*args) - reverse = (args.size == 2) || coordinates?(args.first) - results(args.join(","), reverse).map{ |r| result_class.new(r) } + def search(query, *args) + # convert coordinates as separate arguments to an array + if query.is_a?(Numeric) and args.first.is_a?(Numeric) + warn "DEPRECATION WARNING: Instead of passing latitude/longitude as separate arguments to the search method, please pass an array: [#{query},#{args.first}]. The old argument format will not be supported in Geocoder v.1.0." + query = [query, args.first] + end + + # if coordinates given as string, turn into array + query = query.split(/\s*,\s*/) if coordinates?(query) + + if query.is_a?(Array) + reverse = true + query = query.join(',') + else + reverse = false + end + results(query, reverse).map{ |r| result_class.new(r) } end private # ------------------------------------------------------------- @@ -111,17 +125,17 @@ ## # Is the given string a loopback IP address? # def loopback_address?(ip) - !!(ip == "0.0.0.0" or ip.match(/^127/)) + !!(ip == "0.0.0.0" or ip.to_s.match(/^127/)) end ## # Does the given string look like latitude/longitude coordinates? # def coordinates?(value) - !!value.to_s.match(/^[0-9\.\-]+, ?[0-9\.\-]+$/) + !!value.to_s.match(/^[0-9\.\-]+, *[0-9\.\-]+$/) end ## # Simulate ActiveSupport's Object#to_query. # Removes any keys with nil value.