Sha256: 81d3963e0372a98f139bf1d45e712838d0ec40ef4e2304a8054b4d7f49857568

Contents?: true

Size: 1.48 KB

Versions: 54

Compression:

Stored size: 1.48 KB

Contents

require 'geocoder/results/nominatim'
module Geocoder::Result
  Nominatim.class_eval do
    
    
    ## Additional Stuff
    
    def city
      %w[city town village hamlet].each do |key|
        return @data['address'][key] if @data['address'].key?(key)
      end
      @data['display_name'].split(',').count > 3 ? @data['display_name'].split(',')[-3].strip : nil
      # return nil
    end
    
    def street
      %w[road pedestrian highway].each do |key|
        return @data['address'][key] if @data['address'].key?(key)
      end
      return nil
    end
    
    def street_number
      @data['address']['house_number']
    end
    
    def country_code
      @data['address']['country_code'].present? ? @data['address']['country_code'].to_s.upcase : nil
    end
    
    def district
      @data['address']['city_district'].present? ? @data['address']['city_district'] : nil
    end
    
    def subdistrict
      @data['address']['suburb'].present? ? @data['address']['suburb'] : nil
    end
    
    def city_code
      %w[city town village hamlet].each do |key|
        return @data['address'][key] if @data['address'].key?(key)
      end
      @data['display_name'].split(',').count > 3 ? @data['display_name'].split(',')[-3].strip : nil
    end
    
    def district_code
      @data['address']['city_district'].present? ? @data['address']['city_district'] : nil
    end
    
    def subdistrict_code
      @data['address']['suburb'].present? ? @data['address']['suburb'] : nil
    end
    
    
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

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