class Geokit::Geocoders::BaseIpGeocoder
Constants
- NON_ROUTABLE_IP_RANGES
A number of non-routable IP ranges.
– Sources for these:
RFC 3330: Special-Use IPv4 Addresses The bogon list: http://www.cymru.com/Documents/bogon-list.html
Public Class Methods
ip?(ip)
click to toggle source
# File lib/geokit/geocoders/base_ip.rb, line 29 def self.ip?(ip) /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$/.match(ip) end
private_ip_address?(ip)
click to toggle source
Checks whether the IP address belongs to a private address range.
This function is used to reduce the number of useless queries made to the geocoding service. Such queries can occur frequently during integration tests.
# File lib/geokit/geocoders/base_ip.rb, line 43 def self.private_ip_address?(ip) NON_ROUTABLE_IP_RANGES.any? { |range| range.include?(ip) } end
process(format, ip)
click to toggle source
Calls superclass method
Geokit::Geocoders::Geocoder::process
# File lib/geokit/geocoders/base_ip.rb, line 33 def self.process(format, ip) return GeoLoc.new unless valid_ip?(ip) super(format, submit_url(ip)) end
valid_ip?(ip)
click to toggle source
# File lib/geokit/geocoders/base_ip.rb, line 25 def self.valid_ip?(ip) ip?(ip) && !private_ip_address?(ip) end