Class: Where::Address

Inherits:
Base
  • Object
show all
Defined in:
lib/where/address.rb

Constant Summary collapse

GEOCODER_URL =
'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address='

Instance Attribute Summary

Attributes inherited from Base

#accuracy, #city, #country_code, #country_name, #lat, #lng, #neighborhood, #postal_code, #region_code, #region_name, #street, #street_number

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#address, #attributes=, #country, #initialize, #region, #street_address, #success?

Constructor Details

This class inherits a constructor from Where::Base

Class Method Details

.geocode(address, opts = {}) ⇒ Object



5
6
7
# File 'lib/where/address.rb', line 5

def self.geocode(address, opts={})
  super(address, GEOCODER_URL)
end

Instance Method Details

#address_components=(components = []) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/where/address.rb', line 21

def address_components=(components=[])
  components.each do |component|
    type = determine_type(component['types'])
    next if type.empty?

    if %w(region country).include?(type)
      send("#{type}_code=", component['short_name'])
      send("#{type}_name=", component['long_name'])
    else
      send("#{type}=", component['long_name'])
    end
  end
end

#formatted_address=(val) ⇒ Object



17
18
19
# File 'lib/where/address.rb', line 17

def formatted_address=(val)
  @address = val
end

#geometry=(val = {}) ⇒ Object



35
36
37
# File 'lib/where/address.rb', line 35

def geometry=(val={})
  self.attributes = val['location']
end

#results=(results_array = []) ⇒ Object



9
10
11
# File 'lib/where/address.rb', line 9

def results=(results_array=[])
  results_array.each { |result| self.attributes = result }
end

#types=(val = []) ⇒ Object



13
14
15
# File 'lib/where/address.rb', line 13

def types=(val=[])
  @accuracy = determine_type(val)
end