Class: Drifter::Location

Inherits:
Object
  • Object
show all
Includes:
Locatable
Defined in:
lib/drifter/location.rb,
lib/drifter/location/locatable.rb

Overview

Drifter.geocode() returns an array of Drifter::Location objects Depending on the geocoder used, Location objects are populated with a bunch of common attributes - see the docs for individual geocoders for a list of attributes they set:

Drifter::Geocoders::Google.geocode() Drifter::Geocoders::Yahoo.geocode()

Additional data returned by the geocoder can be accessed via the data() method

Defined Under Namespace

Modules: Locatable

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Locatable

#distance_to

Instance Attribute Details

#addressObject

Returns the value of attribute address.



20
21
22
# File 'lib/drifter/location.rb', line 20

def address
  @address
end

#cityObject

Returns the value of attribute city.



21
22
23
# File 'lib/drifter/location.rb', line 21

def city
  @city
end

#countryObject

Returns the value of attribute country.



25
26
27
# File 'lib/drifter/location.rb', line 25

def country
  @country
end

#country_codeObject

Returns the value of attribute country_code.



26
27
28
# File 'lib/drifter/location.rb', line 26

def country_code
  @country_code
end

#geocoderObject

Returns the value of attribute geocoder.



18
19
20
# File 'lib/drifter/location.rb', line 18

def geocoder
  @geocoder
end

#latObject

Returns the value of attribute lat.



27
28
29
# File 'lib/drifter/location.rb', line 27

def lat
  @lat
end

#lngObject

Returns the value of attribute lng.



28
29
30
# File 'lib/drifter/location.rb', line 28

def lng
  @lng
end

#post_codeObject

Returns the value of attribute post_code.



24
25
26
# File 'lib/drifter/location.rb', line 24

def post_code
  @post_code
end

#raw_dataObject

Returns the value of attribute raw_data.



16
17
18
# File 'lib/drifter/location.rb', line 16

def raw_data
  @raw_data
end

#raw_data_formatObject

Returns the value of attribute raw_data_format.



17
18
19
# File 'lib/drifter/location.rb', line 17

def raw_data_format
  @raw_data_format
end

#stateObject

Returns the value of attribute state.



22
23
24
# File 'lib/drifter/location.rb', line 22

def state
  @state
end

#state_codeObject

Returns the value of attribute state_code.



23
24
25
# File 'lib/drifter/location.rb', line 23

def state_code
  @state_code
end

Instance Method Details

#dataObject

returns a Hash containing the geocoder’s raw data. This is geocoder specific and you should read the provider’s docs to see what data they return in each geocoding response



33
34
35
36
37
38
39
# File 'lib/drifter/location.rb', line 33

def data
  @data ||= case raw_data_format
    when :hash then return raw_data
    when :json then return JSON.parse(raw_data)
    else nil
  end
end