class Geocoder::Result::Yandex

Constants

ADDRESS_DETAILS

It may resides on the top (ADDRESS_DETAILS) level. example: ‘Baltic Sea’ “AddressDetails”: {

"Locality": {
  "Premise": {
    "PremiseName": "Baltic Sea"
  }
}

}

ADMIN_LEVEL

On ADMIN_LEVEL (usually state or city) example: ‘Moscow, Tverskaya’ “AddressDetails”: {

"Country": {
  "AddressLine": "Moscow, Tverskaya Street",
  "CountryNameCode": "RU",
  "CountryName": "Russia",
  "AdministrativeArea": {
    "AdministrativeAreaName": "Moscow",
    "Locality": {
      "LocalityName": "Moscow",
      "Thoroughfare": {
        "ThoroughfareName": "Tverskaya Street"
      }
    }
  }
}

}

COUNTRY_LEVEL

On COUNTRY_LEVEL. example: ‘Potomak’ “AddressDetails”: {

"Country": {
  "AddressLine": "reka Potomak",
  "CountryNameCode": "US",
  "CountryName": "United States of America",
  "Locality": {
    "Premise": {
      "PremiseName": "reka Potomak"
    }
  }
}

}

DEPENDENT_LOCALITY_1

On DEPENDENT_LOCALITY_1 (may refer to district of city) example: ‘Paris, Etienne Marcel’ “AddressDetails”: {

"Country": {
  "AddressLine": "Île-de-France, Paris, 1er Arrondissement, Rue Étienne Marcel",
  "CountryNameCode": "FR",
  "CountryName": "France",
  "AdministrativeArea": {
    "AdministrativeAreaName": "Île-de-France",
    "Locality": {
      "LocalityName": "Paris",
      "DependentLocality": {
        "DependentLocalityName": "1er Arrondissement",
        "Thoroughfare": {
          "ThoroughfareName": "Rue Étienne Marcel"
        }
      }
    }
  }
}

}

DEPENDENT_LOCALITY_2

“AddressDetails”: {

"Country": {
  "AddressLine": "İstanbul, Fatih, Saraç İshak Mah., Mabeyinci Yokuşu, 17",
  "CountryNameCode": "TR",
  "CountryName": "Turkey",
  "AdministrativeArea": {
    "AdministrativeAreaName": "İstanbul",
    "SubAdministrativeArea": {
      "SubAdministrativeAreaName": "Fatih",
      "Locality": {
        "DependentLocality": {
          "DependentLocalityName": "Saraç İshak Mah.",
          "Thoroughfare": {
            "ThoroughfareName": "Mabeyinci Yokuşu",
            "Premise": {
              "PremiseNumber": "17"
            }
          }
        }
      }
    }
  }
}

}

SUBADMIN_LEVEL

On SUBADMIN_LEVEL (may refer to urban district) example: ‘Moscow Region, Krasnogorsk’ “AddressDetails”: {

"Country": {
  "AddressLine": "Moscow Region, Krasnogorsk",
  "CountryNameCode": "RU",
  "CountryName": "Russia",
  "AdministrativeArea": {
    "AdministrativeAreaName": "Moscow Region",
    "SubAdministrativeArea": {
      "SubAdministrativeAreaName": "gorodskoy okrug Krasnogorsk",
      "Locality": {
        "LocalityName": "Krasnogorsk"
      }
    }
  }
}

}

Public Instance Methods

address(_format = :full) click to toggle source
# File lib/geocoder/results/yandex.rb, line 169
def address(_format = :full)
  @data['GeoObject']['metaDataProperty']['GeocoderMetaData']['text']
end
city() click to toggle source
# File lib/geocoder/results/yandex.rb, line 173
def city
  result =
    if state.empty?
      find_in_hash(@data, *COUNTRY_LEVEL, 'Locality', 'LocalityName')
    elsif sub_state.empty?
      find_in_hash(@data, *ADMIN_LEVEL, 'Locality', 'LocalityName')
    else
      find_in_hash(@data, *SUBADMIN_LEVEL, 'Locality', 'LocalityName')
    end

  result || ""
end
coordinates() click to toggle source
# File lib/geocoder/results/yandex.rb, line 165
def coordinates
  @data['GeoObject']['Point']['pos'].split(' ').reverse.map(&:to_f)
end
country() click to toggle source
# File lib/geocoder/results/yandex.rb, line 186
def country
  find_in_hash(@data, *COUNTRY_LEVEL, 'CountryName') || ""
end
country_code() click to toggle source
# File lib/geocoder/results/yandex.rb, line 190
def country_code
  find_in_hash(@data, *COUNTRY_LEVEL, 'CountryNameCode') || ""
end
kind() click to toggle source
# File lib/geocoder/results/yandex.rb, line 224
def kind
  @data['GeoObject']['metaDataProperty']['GeocoderMetaData']['kind']
end
postal_code() click to toggle source
# File lib/geocoder/results/yandex.rb, line 219
def postal_code
  return "" unless premise.is_a?(Hash)
  find_in_hash(premise, 'PostalCode', 'PostalCodeNumber') || ""
end
precision() click to toggle source
# File lib/geocoder/results/yandex.rb, line 228
def precision
  @data['GeoObject']['metaDataProperty']['GeocoderMetaData']['precision']
end
premise_name() click to toggle source
# File lib/geocoder/results/yandex.rb, line 215
def premise_name
  premise.is_a?(Hash) ? premise.fetch('PremiseName', "") : ""
end
state() click to toggle source
# File lib/geocoder/results/yandex.rb, line 194
def state
  find_in_hash(@data, *ADMIN_LEVEL, 'AdministrativeAreaName') || ""
end
state_code() click to toggle source
# File lib/geocoder/results/yandex.rb, line 203
def state_code
  ""
end
street() click to toggle source
# File lib/geocoder/results/yandex.rb, line 207
def street
  thoroughfare_data.is_a?(Hash) ? thoroughfare_data['ThoroughfareName'] : ""
end
street_number() click to toggle source
# File lib/geocoder/results/yandex.rb, line 211
def street_number
  premise.is_a?(Hash) ? premise.fetch('PremiseNumber', "") : ""
end
sub_state() click to toggle source
# File lib/geocoder/results/yandex.rb, line 198
def sub_state
  return "" if state.empty?
  find_in_hash(@data, *SUBADMIN_LEVEL, 'SubAdministrativeAreaName') || ""
end
viewport() click to toggle source
# File lib/geocoder/results/yandex.rb, line 232
def viewport
  envelope = @data['GeoObject']['boundedBy']['Envelope'] || fail
  east, north = envelope['upperCorner'].split(' ').map(&:to_f)
  west, south = envelope['lowerCorner'].split(' ').map(&:to_f)
  [south, west, north, east]
end