lib/geokit/mappable.rb in darrell-geokit-1.4.1.1 vs lib/geokit/mappable.rb in darrell-geokit-1.5.0.1

- old
+ new

@@ -334,36 +334,38 @@ # # Then, for the user of the result: # # puts geo.full_address # just like usual # puts geo.all.size => 3 # there's three results total - # puts geo.all.first # all is just an array or additional geolocs, + # puts geo.all.first # all is just an array or additional geolocs, # so do what you want with it class GeoLoc < LatLng # Location attributes. Full address is a concatenation of all values. For example: # 100 Spear St, San Francisco, CA, 94101, US - attr_accessor :street_address, :city, :state, :zip, :country_code, :full_address, :all + # Street number and street name are extracted from the street address attribute if they don't exist + attr_accessor :street_number,:street_name,:street_address, :city, :state, :zip, :country_code, :country, :full_address, :all, :district, :province # Attributes set upon return from geocoding. Success will be true for successful # geocode lookups. The provider will be set to the name of the providing geocoder. # Finally, precision is an indicator of the accuracy of the geocoding. attr_accessor :success, :provider, :precision, :suggested_bounds - # Street number and street name are extracted from the street address attribute. - attr_reader :street_number, :street_name # accuracy is set for Yahoo and Google geocoders, it is a numeric value of the # precision. see http://code.google.com/apis/maps/documentation/geocoding/#GeocodingAccuracy attr_accessor :accuracy # Constructor expects a hash of symbols to correspond with attributes. def initialize(h={}) @all = [self] @street_address=h[:street_address] + @street_number=nil + @street_name=nil @city=h[:city] @state=h[:state] @zip=h[:zip] - @country_code=h[:country_code] + @country_code=h[:country_code] + @province = h[:province] @success=false @precision='unknown' @full_address=nil super(h[:lat],h[:lng]) end @@ -382,25 +384,26 @@ # from the parts of the address we do have. def full_address @full_address ? @full_address : to_geocodeable_s end - # Extracts the street number from the street address if the street address - # has a value. + # Extracts the street number from the street address where possible. def street_number - street_address[/(\d*)/] if street_address + @street_number ||= street_address[/(\d*)/] if street_address + @street_number end - # Returns the street name portion of the street address. + # Returns the street name portion of the street address where possible def street_name - street_address[street_number.length, street_address.length].strip if street_address + @street_name||=street_address[street_number.length, street_address.length].strip if street_address + @street_name end # gives you all the important fields as key-value pairs def hash res={} - [:success,:lat,:lng,:country_code,:city,:state,:zip,:street_address,:provider,:full_address,:is_us?,:ll,:precision].each { |s| res[s] = self.send(s.to_s) } + [:success,:lat,:lng,:country_code,:city,:state,:zip,:street_address,:province,:district,:provider,:full_address,:is_us?,:ll,:precision].each { |s| res[s] = self.send(s.to_s) } res end alias to_hash hash # Sets the city after capitalizing each word within the city name. @@ -408,17 +411,20 @@ @city = Geokit::Inflector::titleize(city) if city end # Sets the street address after capitalizing each word within the street address. def street_address=(address) - #@street_address = Geokit::Inflector::titleize(address) if address - @street_address = address if address + if address and not ['google','google3'].include?(self.provider) + @street_address = Geokit::Inflector::titleize(address) + else + @street_address = address + end end # Returns a comma-delimited string consisting of the street address, city, state, # zip, and country code. Only includes those attributes that are non-blank. def to_geocodeable_s - a=[street_address, city, state, zip, country_code].compact + a=[street_address, district, city, province, state, zip, country_code].compact a.delete_if { |e| !e || e == '' } a.join(', ') end def to_yaml_properties