From a5aeaabd2e90a75117940875b0ff470397c0e4dc Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 30 Jan 2017 21:35:22 -0500 Subject: [PATCH] Revert "Refactor calculations (#1116)" This reverts commit 1c306367588f61b418a0f41f049f73cfd9f94897. --- lib/geocoder/calculations.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/geocoder/calculations.rb b/lib/geocoder/calculations.rb index c36e5932..84ab009c 100644 --- a/lib/geocoder/calculations.rb +++ b/lib/geocoder/calculations.rb @@ -42,7 +42,12 @@ module Geocoder # Returns true if all given arguments are valid latitude/longitude values. # def coordinates_present?(*args) - args.all? { |a| a.is_a? Numeric and !a.to_f.nan? } + args.each do |a| + # note that Float::NAN != Float::NAN + # still, this could probably be improved: + return false if (!a.is_a?(Numeric) or a.to_s == "NaN") + end + true end ## @@ -392,8 +397,13 @@ module Geocoder def extract_coordinates(point) case point when Array - if point.size == 2 and coordinates_present?(*point) - return point.map {|coords| coords.to_f} + if point.size == 2 + lat, lon = point + if !lat.nil? && lat.respond_to?(:to_f) and + !lon.nil? && lon.respond_to?(:to_f) + then + return [ lat.to_f, lon.to_f ] + end end when String point = Geocoder.coordinates(point) and return point -- GitLab