lib/geokit/geocoders.rb in andre-geokit-1.2.5 vs lib/geokit/geocoders.rb in andre-geokit-1.2.6

- old
+ new

@@ -103,19 +103,19 @@ # Main method which calls the do_geocode template method which subclasses # are responsible for implementing. Returns a populated GeoLoc or an # empty one with a failed success code. def self.geocode(address) res = do_geocode(address) - return res.success ? res : GeoLoc.new + return res.success? ? res : GeoLoc.new end # Main method which calls the do_reverse_geocode template method which subclasses # are responsible for implementing. Returns a populated GeoLoc or an # empty one with a failed success code. def self.reverse_geocode(latlng) res = do_reverse_geocode(latlng) - return res.success ? res : GeoLoc.new + return res.success? ? res : GeoLoc.new end # Call the geocoder service using the timeout if configured. def self.call_geocoder_service(url) timeout(Geokit::Geocoders::timeout) { return self.do_get(url) } if Geokit::Geocoders::timeout @@ -398,11 +398,11 @@ if doc.elements['//kml/Response/Status/code'].text == '200' geoloc = nil # Google can return multiple results as //Placemark elements. # iterate through each and extract each placemark as a geoloc doc.each_element('//Placemark') do |e| - extracted_geoloc = extract_placemark(e) # g is now an instance of Geoloc + extracted_geoloc = extract_placemark(e) # g is now an instance of GeoLoc if geoloc.nil? # first time through, geoloc is still nil, so we make it the geoloc we just extracted geoloc = extracted_geoloc else # second (and subsequent) iterations, we push additional @@ -490,11 +490,11 @@ # Given an IP address, returns a GeoLoc instance which contains latitude, # longitude, city, and country code. Sets the success attribute to false if the ip # parameter does not match an ip address. def self.do_geocode(ip) - return Geoloc.new if '0.0.0.0' == ip + return GeoLoc.new if '0.0.0.0' == ip return GeoLoc.new unless /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$/.match(ip) url = "http://api.hostip.info/get_html.php?ip=#{ip}&position=true" response = self.call_geocoder_service(url) response.is_a?(Net::HTTPSuccess) ? parse_body(response.body) : GeoLoc.new rescue @@ -548,10 +548,10 @@ def self.do_geocode(address) Geokit::Geocoders::provider_order.each do |provider| begin klass = Geokit::Geocoders.const_get "#{provider.to_s.capitalize}Geocoder" res = klass.send :geocode, address - return res if res.success + return res if res.success? rescue logger.error("Something has gone very wrong during geocoding, OR you have configured an invalid class name in Geokit::Geocoders::provider_order. Address: #{address}. Provider: #{provider}") end end # If we get here, we failed completely.