Class: Drifter::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/drifter/location.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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addressObject

Returns the value of attribute address.



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

def address
  @address
end

#cityObject

Returns the value of attribute city.



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

def city
  @city
end

#countryObject

Returns the value of attribute country.



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

def country
  @country
end

#country_codeObject

Returns the value of attribute country_code.



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

def country_code
  @country_code
end

#geocoderObject

Returns the value of attribute geocoder.



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

def geocoder
  @geocoder
end

#latObject

Returns the value of attribute lat.



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

def lat
  @lat
end

#lngObject

Returns the value of attribute lng.



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

def lng
  @lng
end

#post_codeObject

Returns the value of attribute post_code.



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

def post_code
  @post_code
end

#raw_dataObject

Returns the value of attribute raw_data.



14
15
16
# File 'lib/drifter/location.rb', line 14

def raw_data
  @raw_data
end

#raw_data_formatObject

Returns the value of attribute raw_data_format.



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

def raw_data_format
  @raw_data_format
end

#stateObject

Returns the value of attribute state.



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

def state
  @state
end

#state_codeObject

Returns the value of attribute state_code.



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

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



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

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