Class: Grobi::Placemark

Inherits:
Object
  • Object
show all
Defined in:
lib/grobi/maps.rb

Direct Known Subclasses

Place

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Placemark

Returns a new instance of Placemark.



40
41
42
43
44
# File 'lib/grobi/maps.rb', line 40

def initialize(json)
  super()
  update(json)
  self
end

Instance Attribute Details

#cityObject

Returns the value of attribute city.



38
39
40
# File 'lib/grobi/maps.rb', line 38

def city
  @city
end

#countryObject

Returns the value of attribute country.



38
39
40
# File 'lib/grobi/maps.rb', line 38

def country
  @country
end

#establishmentObject

Returns the value of attribute establishment.



38
39
40
# File 'lib/grobi/maps.rb', line 38

def establishment
  @establishment
end

#formatted_addressObject

Returns the value of attribute formatted_address.



38
39
40
# File 'lib/grobi/maps.rb', line 38

def formatted_address
  @formatted_address
end

#latitudeObject

Returns the value of attribute latitude.



38
39
40
# File 'lib/grobi/maps.rb', line 38

def latitude
  @latitude
end

#localityObject

Returns the value of attribute locality.



38
39
40
# File 'lib/grobi/maps.rb', line 38

def locality
  @locality
end

#longitudeObject

Returns the value of attribute longitude.



38
39
40
# File 'lib/grobi/maps.rb', line 38

def longitude
  @longitude
end

#numberObject

Returns the value of attribute number.



38
39
40
# File 'lib/grobi/maps.rb', line 38

def number
  @number
end

#postal_codeObject

Returns the value of attribute postal_code.



38
39
40
# File 'lib/grobi/maps.rb', line 38

def postal_code
  @postal_code
end

#routeObject

Returns the value of attribute route.



38
39
40
# File 'lib/grobi/maps.rb', line 38

def route
  @route
end

Instance Method Details

#update(json) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/grobi/maps.rb', line 46

def update(json)
  @formatted_address = json['formatted_address']
  if json['geometry']
    @longitude = json['geometry']['location']['lng']
    @latitude = json['geometry']['location']['lat']
  end
  if json['address_components']
    components = json['address_components'].each do |component|
      @establishment = component['long_name'] if component['types'].include?('establishment')
      @country = component['short_name'] if component['types'].include?('country')
      @city = component['long_name'] if component['types'].include?('administrative_area_level_2')
      @locality = component['long_name'] if component['types'].include?('locality')
      @route = component['long_name'] if component['types'].include?('route')
      @number = component['long_name'] if component['types'].include?('street_number')
      @postal_code = component['long_name'] if component['types'].include?('postal_code')
    end
  end
end