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, #province, #province_code

Constructor Details

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

Instance Method Details

#addressObject



50
51
52
# File 'lib/geocoder/results/mapbox.rb', line 50

def address
  [place_name, street, city, state, postal_code, country].compact.join(", ")
end

#cityObject



26
27
28
# File 'lib/geocoder/results/mapbox.rb', line 26

def city
  @data['context'].map { |c| c['text'] if c['id'] =~ /place/ }.compact.first
end

#coordinatesObject



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

def coordinates
  [latitude, longitude]
end

#countryObject Also known as: country_code



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

def country
  @data['context'].map { |c| c['text'] if c['id'] =~ /country/ }.compact.first
end

#latitudeObject



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

def latitude
  @latitude ||= @data["geometry"]["coordinates"].last.to_f
end

#longitudeObject



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

def longitude
  @longitude ||= @data["geometry"]["coordinates"].first.to_f
end

#neighborhoodObject



46
47
48
# File 'lib/geocoder/results/mapbox.rb', line 46

def neighborhood
  @data['context'].map { |c| c['text'] if c['id'] =~ /neighborhood/ }.compact.first
end

#place_nameObject



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

def place_name
  @data['text']
end

#postal_codeObject



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

def postal_code
  @data['context'].map { |c| c['text'] if c['id'] =~ /postcode/ }.compact.first
end

#stateObject Also known as: state_code



30
31
32
# File 'lib/geocoder/results/mapbox.rb', line 30

def state
  @data['context'].map { |c| c['text'] if c['id'] =~ /region/ }.compact.first
end

#streetObject



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

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