Sha256: 223e3850964f419d8718f5ba0d2e217b2c8500d562f6a8732c5ac907fb761dd8

Contents?: true

Size: 869 Bytes

Versions: 3

Compression:

Stored size: 869 Bytes

Contents

require 'sora_geocoding/results/base'

module SoraGeocoding
  module Results
    #
    # get the latitude and longitude of the Yahoo! Geocoder API
    #
    class YahooGeocoder < Base
      def coordinates
        check_data_for_errors!
        lonlat = @data.elements['/YDF/Feature/Geometry/Coordinates'].get_text.to_s.split(',')
        { lat: lonlat[1], lon: lonlat[0] }
      end

      def check_data_for_errors!
        if @data.elements['/Error']
          message = @data.elements['/Error/Message'].get_text.to_s
          code = @data.elements['/Error/Code'].get_text.to_s
          SoraGeocoding.log(:error, "Yahoo Geocoder API error: #{code} #{message}")
        elsif @data.elements['/YDF'].attributes['totalResultsReturned'].to_i < 1
          SoraGeocoding.log(:error, 'Yahoo Geocoder API error: 001 Zero Results')
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sora_geocoding-0.2.2 lib/sora_geocoding/results/yahoo_geocoder.rb
sora_geocoding-0.2.0 lib/sora_geocoding/results/yahoo_geocoder.rb
sora_geocoding-0.1.0 lib/sora_geocoding/results/yahoo_geocoder.rb