diff --git a/lib/geocoder.rb b/lib/geocoder.rb index b7c8be64eee5992e7a88ec9cebb46d82965b2c9f..8aec8c33ca3a7c257c0cd352b68b6a0e63956e92 100644 --- a/lib/geocoder.rb +++ b/lib/geocoder.rb @@ -10,7 +10,7 @@ module Geocoder # Search for information about an address or a set of coordinates. # def search(*args) - return [] if args[0].nil? || args[0] == "" + return [] if blank_query?(args[0]) ip = (args.size == 1 and ip_address?(args.first)) lookup(ip).search(*args) end @@ -81,6 +81,13 @@ module Geocoder def ip_address?(value) value.match /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/ end + + ## + # Is the given search query blank? (ie, should we not bother searching?) + # + def blank_query?(value) + !value.to_s.match(/[A-z0-9]/) + end end Geocoder::Railtie.insert