lib/geokit/geo_loc.rb in geokit-1.10.0 vs lib/geokit/geo_loc.rb in geokit-1.11.0

- old
+ new

@@ -23,55 +23,61 @@ # Location attributes. Full address is a concatenation of all values. # For example: # 100 Spear St, San Francisco, CA, 94101, US # 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, - :state_name, :state_code, :zip, :country_code, :country - attr_accessor :full_address, :all, :district, :province, :sub_premise, + attr_accessor :state_name, :state_code, :zip, :country_code, :country + attr_accessor :all, :district, :sub_premise, :neighborhood + attr_writer :state, :full_address, :street_number, :street_name, :formatted_address + attr_reader :city, :street_address # 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, :place_id, - :formatted_address + attr_accessor :success, :provider, :precision, :suggested_bounds, :place_id # 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 # FCC Attributes attr_accessor :district_fips, :state_fips, :block_fips + def province + state + end + # Constructor expects a hash of symbols to correspond with attributes. def initialize(h = {}) @all = [self] - + + # sanatises the GeoLoc object so that it conforms to [] + h = h.to_hash + @street_address = h[:street_address] @sub_premise = nil @street_number = nil @street_name = nil @city = h[:city] @state = h[:state] @state_code = h[:state_code] @state_name = h[:state_name] @zip = h[:zip] @country_code = h[:country_code] - @province = h[:province] @success = false - @precision = "unknown" + @precision = 'unknown' @full_address = nil super(h[:lat], h[:lng]) end def state @state || @state_code || @state_name end # Returns true if geocoded to the United States. def is_us? - country_code == "US" + country_code == 'US' end def success? success == true end @@ -102,11 +108,11 @@ # gives you all the important fields as key-value pairs def hash res = {} fields = [:success, :lat, :lng, :country_code, :city, :state, :zip, - :street_address, :province, :district, :provider, :full_address, :is_us?, + :street_address, :district, :provider, :full_address, :is_us?, :ll, :precision, :district_fips, :state_fips, :block_fips, :sub_premise] fields.each { |s| res[s] = send(s.to_s) } res end alias_method :to_hash, :hash @@ -117,27 +123,27 @@ end # Sets the street address after capitalizing each word within the street # address. def street_address=(address) - @street_address = if address && provider != "google" - Geokit::Inflector.titleize(address) - else - address - end + @street_address = if address && provider != 'google' + Geokit::Inflector.titleize(address) + else + 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, district, city, province, state, zip, country_code].compact - a.delete_if { |e| !e || e == "" } - a.join(", ") + a = [street_address, district, city, state, zip, country_code].compact + a.delete_if { |e| !e || e == '' } + a.join(', ') end def to_yaml_properties - (instance_variables - ["@all", :@all]).sort + (instance_variables - ['@all', :@all]).sort end def encode_with(coder) to_yaml_properties.each do |name| coder[name[1..-1].to_s] = instance_variable_get(name.to_s)