Class: Geocoder::Result::Mapbox

Inherits:
Base
  • Object
show all
Defined in:
lib/geocoder/results/mapbox.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

#addressObject



58
59
60
# File 'lib/geocoder/results/mapbox.rb', line 58

def address
  data['place_name']
end

#cityObject



18
19
20
# File 'lib/geocoder/results/mapbox.rb', line 18

def city
  data_part('place') || context_part('place')
end

#coordinatesObject



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

def coordinates
  data['geometry']['coordinates'].reverse.map(&:to_f)
end

#countryObject



40
41
42
# File 'lib/geocoder/results/mapbox.rb', line 40

def country
  data_part('country') || context_part('country')
end

#country_codeObject



44
45
46
47
48
49
50
51
52
# File 'lib/geocoder/results/mapbox.rb', line 44

def country_code
  if id_matches_name?(data['id'], 'country')
    value = data['properties']['short_code']
  else
    value = context_part('country', 'short_code')
  end

  value.upcase unless value.nil?
end

#neighborhoodObject



54
55
56
# File 'lib/geocoder/results/mapbox.rb', line 54

def neighborhood
  data_part('neighborhood') || context_part('neighborhood')
end

#place_nameObject



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

def place_name
  data['text']
end

#postal_codeObject



36
37
38
# File 'lib/geocoder/results/mapbox.rb', line 36

def postal_code
  data_part('postcode') || context_part('postcode')
end

#stateObject



22
23
24
# File 'lib/geocoder/results/mapbox.rb', line 22

def state
  data_part('region') || context_part('region')
end

#state_codeObject



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

def state_code
  if id_matches_name?(data['id'], 'region')
    value = data['properties']['short_code']
  else
    value = context_part('region', 'short_code')
  end

  value.split('-').last unless value.nil?
end

#streetObject



14
15
16
# File 'lib/geocoder/results/mapbox.rb', line 14

def street
  data['properties']['address']
end