Class: Graticule::Geocoder::Mapbox::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/graticule/geocoder/mapbox.rb

Overview

A result looks like: [

{
  "id"=>"address.110173544177",
  "lon"=>-122.02912,
  "lat"=>37.33054,
  "name"=>"1 Infinite Loop",
  "type"=>"address"
}, {
  "id"=>"mapbox-places.95014",
  "name"=>"Cupertino",
  "type"=>"city"
}, {
  "id"=>"province.1112151813",
  "name"=>"California",
  "type"=>"province"
}, {
  "id"=>"country.4150104525",
  "name"=>"United States",
  "type"=>"country"
}

]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Result

Returns a new instance of Result.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/graticule/geocoder/mapbox.rb', line 41

def initialize(input)
  self.precision = ::Graticule::Precision::Unknown
  self.lat = input.first["lat"]
  self.lon = input.first["lon"]

  input.each do |tuple|
    case tuple["type"]
      when "zipcode"
        self.postal_code = tuple["name"]
        set_higher_precision(::Graticule::Precision::PostalCode)
      when "address"
        self.address = tuple["name"]
        set_higher_precision(::Graticule::Precision::Address)
      when "city"
        self.city = tuple["name"]
        set_higher_precision(::Graticule::Precision::Locality)
        self.postal_code = tuple["id"].split(".")[1]
      when "province"
        self.province = tuple["name"]
        set_higher_precision(::Graticule::Precision::Region)
      when "country"
        self.country = tuple["name"]
        set_higher_precision(::Graticule::Precision::Country)
    end
  end
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



39
40
41
# File 'lib/graticule/geocoder/mapbox.rb', line 39

def address
  @address
end

#cityObject

Returns the value of attribute city.



39
40
41
# File 'lib/graticule/geocoder/mapbox.rb', line 39

def city
  @city
end

#countryObject

Returns the value of attribute country.



39
40
41
# File 'lib/graticule/geocoder/mapbox.rb', line 39

def country
  @country
end

#latObject

Returns the value of attribute lat.



39
40
41
# File 'lib/graticule/geocoder/mapbox.rb', line 39

def lat
  @lat
end

#lonObject

Returns the value of attribute lon.



39
40
41
# File 'lib/graticule/geocoder/mapbox.rb', line 39

def lon
  @lon
end

#postal_codeObject

Returns the value of attribute postal_code.



39
40
41
# File 'lib/graticule/geocoder/mapbox.rb', line 39

def postal_code
  @postal_code
end

#precisionObject

Returns the value of attribute precision.



39
40
41
# File 'lib/graticule/geocoder/mapbox.rb', line 39

def precision
  @precision
end

#provinceObject

Returns the value of attribute province.



39
40
41
# File 'lib/graticule/geocoder/mapbox.rb', line 39

def province
  @province
end