Sha256: 3c359f9f3a1a0d0a581275bf103788d995589c59b6589ee01b75bed59c914584

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

require 'geocoder2/results/base'

module Geocoder2::Result
  class Yandex < Base

    def coordinates
      @data['GeoObject']['Point']['pos'].split(' ').reverse.map(&:to_f)
    end

    def address(format = :full)
      @data['GeoObject']['metaDataProperty']['Geocoder2MetaData']['text']
    end

    def city
      if state.empty? and address_details.has_key? 'Locality'
        address_details['Locality']['LocalityName']
      elsif sub_state.empty?
        address_details['AdministrativeArea']['Locality']['LocalityName']
      elsif not sub_state_city.empty?
        sub_state_city
      else
        ""
      end
    end

    def country
      address_details['CountryName']
    end

    def country_code
      address_details['CountryNameCode']
    end

    def state
      if address_details['AdministrativeArea']
        address_details['AdministrativeArea']['AdministrativeAreaName']
      else
        ""
      end
    end

    def sub_state
      if !state.empty? and address_details['AdministrativeArea']['SubAdministrativeArea']
        address_details['AdministrativeArea']['SubAdministrativeArea']['SubAdministrativeAreaName']
      else
        ""
      end
    end

    def state_code
      ""
    end

    def postal_code
      ""
    end

    def premise_name
      address_details['Locality']['Premise']['PremiseName']
    end

    def precision
      @data['GeoObject']['metaDataProperty']['Geocoder2MetaData']['precision']
    end

    private # ----------------------------------------------------------------

    def address_details
      @data['GeoObject']['metaDataProperty']['Geocoder2MetaData']['AddressDetails']['Country']
    end

    def sub_state_city
      if sub_state && sub_state["Locality"]
        sub_state['Locality']['LocalityName']          
      else
        ""
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geocoder2-0.1.1 lib/geocoder2/results/yandex.rb
geocoder2-0.1.0 lib/geocoder2/results/yandex.rb