lib/where/address.rb in where-0.0.1 vs lib/where/address.rb in where-0.0.2

- old
+ new

@@ -1,58 +1,57 @@ module Where - class Address < Where::Base - class << self - GEOCODER_URL = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' - - def geocode(address, api_url=nil) - super(address, api_url || GEOCODER_URL) - end + class Address < Where::Base + GEOCODER_URL = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' + + def self.geocode(address, opts={}) + super(address, GEOCODER_URL) end - - def results=(results_array = []) - results_array.each { |result| self.new_attributes = result } + + def results=(results_array=[]) + results_array.each { |result| self.attributes = result } end - - def types=(val = []) + + def types=(val=[]) @accuracy = determine_type(val) end - + def formatted_address=(val) @address = val end - - def address_components=(components = []) + + def address_components=(components=[]) components.each do |component| - type = determine_type component['types'] + type = determine_type(component['types']) next if type.empty? - if %w(region country).include? type - self.send "#{type}_code=", component['short_name'] - self.send "#{type}_name=", component['long_name'] + + if %w(region country).include?(type) + send("#{type}_code=", component['short_name']) + send("#{type}_name=", component['long_name']) else - self.send "#{type}=", component['long_name'] + send("#{type}=", component['long_name']) end end end - - def geometry=(val = {}) - self.new_attributes = val['location'] + + def geometry=(val={}) + self.attributes = val['location'] end - - private + private + def determine_type(val = []) { 'street_address' => 'street_address', 'street_number' => 'street_number', 'route' => 'street', 'neighborhood' => 'neighborhood', 'locality' => 'city', 'administrative_area_level_1' => 'region', 'postal_code' => 'postal_code', 'country' => 'country' }.each do |k, v| - return v if val.include? k + return v if val.include?(k) end "" end - + end end