Sha256: e88a9d9e1a4b3de655835ab8cb05b069e814be737cf0a3f2e6078b80da1254db

Contents?: true

Size: 1.57 KB

Versions: 54

Compression:

Stored size: 1.57 KB

Contents

require 'geocoder/results/google'
module Geocoder::Result
  Google.class_eval do
    
    
    ## Additional Stuff
    
    def street
      if route = address_components_of_type(:route).first
        route['long_name']
      end
    end
    
    def district
      fields = [:sublocality_level_1, :sublocality]
      fields.each do |f|
        if entity = address_components_of_type(f).first
          return entity['long_name']
        end
      end
      return nil # no appropriate components found
    end
  
    def subdistrict
      if subdistrict = address_components_of_type(:sublocality_level_2).first
        return subdistrict['long_name']
      end
      return nil # no appropriate components found
    end
    
    
    ## Additional Short-Names
    
    def city_code
      fields = [:locality, :sublocality,
        :administrative_area_level_3,
        :administrative_area_level_2]
      fields.each do |f|
        if entity = address_components_of_type(f).first
          return entity['short_name']
        end
      end
      return nil # no appropriate components found
    end
    
    def district_code
      fields = [:sublocality_level_1, :sublocality]
      fields.each do |f|
        if entity = address_components_of_type(f).first
          return entity['short_name']
        end
      end
      return nil # no appropriate components found
    end
    
    def subdistrict_code
      if subdistrict = address_components_of_type(:sublocality_level_2).first
        return subdistrict['short_name']
      end
      return nil # no appropriate components found
    end
    
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
magic_addresses-0.0.44 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.43 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.42 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.41 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.40 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.39 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.39.rc8 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.39.rc7 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.39.rc6 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.39.rc5 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.39.rc4 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.39.rc3 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.39.rc2 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.39.rc1 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.38 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.38.beta2 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.38.beta1 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.37 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.36 lib/geocoder/results/google_decorator.rb
magic_addresses-0.0.35 lib/geocoder/results/google_decorator.rb