Class: Geocoder::Result::Yandex

Inherits:
Base
  • Object
show all
Defined in:
lib/geocoder/results/yandex.rb

Instance Attribute Summary

Attributes inherited from Base

#cache_hit, #data

Instance Method Summary collapse

Methods inherited from Base

#initialize, #latitude, #longitude, #province, #province_code

Constructor Details

This class inherits a constructor from Geocoder::Result::Base

Instance Method Details

#address(format = :full) ⇒ Object



10
11
12
# File 'lib/geocoder/results/yandex.rb', line 10

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

#cityObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/geocoder/results/yandex.rb', line 14

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

#coordinatesObject



6
7
8
# File 'lib/geocoder/results/yandex.rb', line 6

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

#countryObject



27
28
29
30
31
32
33
# File 'lib/geocoder/results/yandex.rb', line 27

def country
  if address_details
    address_details['CountryName']
  else
    ""
  end
end

#country_codeObject



35
36
37
38
39
40
41
# File 'lib/geocoder/results/yandex.rb', line 35

def country_code
  if address_details
    address_details['CountryNameCode']
  else
    ""
  end
end

#kindObject



79
80
81
# File 'lib/geocoder/results/yandex.rb', line 79

def kind
  @data['GeoObject']['metaDataProperty']['GeocoderMetaData']['kind']
end

#postal_codeObject



63
64
65
# File 'lib/geocoder/results/yandex.rb', line 63

def postal_code
  ""
end

#precisionObject



83
84
85
# File 'lib/geocoder/results/yandex.rb', line 83

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

#premise_nameObject



67
68
69
# File 'lib/geocoder/results/yandex.rb', line 67

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

#stateObject



43
44
45
46
47
48
49
# File 'lib/geocoder/results/yandex.rb', line 43

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

#state_codeObject



59
60
61
# File 'lib/geocoder/results/yandex.rb', line 59

def state_code
  ""
end

#streetObject



71
72
73
# File 'lib/geocoder/results/yandex.rb', line 71

def street
  thoroughfare_data && thoroughfare_data['ThoroughfareName']
end

#street_numberObject



75
76
77
# File 'lib/geocoder/results/yandex.rb', line 75

def street_number
  thoroughfare_data && thoroughfare_data['Premise'] && thoroughfare_data['Premise']['PremiseNumber']
end

#sub_stateObject



51
52
53
54
55
56
57
# File 'lib/geocoder/results/yandex.rb', line 51

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

#viewportObject



87
88
89
90
91
92
# File 'lib/geocoder/results/yandex.rb', line 87

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