class Geocoder::Query

Attributes

options[RW]
text[RW]

Public Class Methods

new(text, options = {}) click to toggle source
# File lib/geocoder/query.rb, line 5
def initialize(text, options = {})
  self.text = text
  self.options = options
end

Public Instance Methods

blank?() click to toggle source

Is the Query blank? (ie, should we not bother searching?) A query is considered blank if its text is nil or empty string AND no URL parameters are specified.

# File lib/geocoder/query.rb, line 53
def blank?
  !params_given? and (
    (text.is_a?(Array) and text.compact.size < 2) or
    text.to_s.match(/\A\s*\z/)
  )
end
coordinates() click to toggle source

Return the latitude/longitude coordinates specified in the query, or nil if none.

# File lib/geocoder/query.rb, line 105
def coordinates
  sanitized_text.split(',') if coordinates?
end
coordinates?() click to toggle source

Does the given string look like latitude/longitude coordinates?

# File lib/geocoder/query.rb, line 94
def coordinates?
  text.is_a?(Array) or (
    text.is_a?(String) and
    !!text.to_s.match(/\A-?[0-9\.]+, *-?[0-9\.]+\z/)
  )
end
execute() click to toggle source
# File lib/geocoder/query.rb, line 10
def execute
  lookup.search(text, options)
end
internal_ip_address?() click to toggle source

Is the Query text a loopback or private IP address?

# File lib/geocoder/query.rb, line 73
def internal_ip_address?
  ip_address? && IpAddress.new(text).internal?
end
ip_address?() click to toggle source

Does the Query text look like an IP address?

Does not check for actual validity, just the appearance of four dot-delimited numbers.

# File lib/geocoder/query.rb, line 66
def ip_address?
  IpAddress.new(text).valid? rescue false
end
language() click to toggle source
# File lib/geocoder/query.rb, line 116
def language
  options[:language]
end
lookup() click to toggle source

Get a Lookup object (which communicates with the remote geocoding API) appropriate to the Query text.

# File lib/geocoder/query.rb, line 34
def lookup
  if !options[:streot_address] and (options[:ip_address] or ip_address?)
    name = options[:ip_lookup] || Configuration.ip_lookup || Geocoder::Lookup.ip_services.first
  else
    name = options[:lookup] || Configuration.lookup || Geocoder::Lookup.street_services.first
  end
  Lookup.get(name)
  return
end
loopback_ip_address?() click to toggle source

Is the Query text a loopback IP address?

# File lib/geocoder/query.rb, line 80
def loopback_ip_address?
  ip_address? && IpAddress.new(text).loopback?
end
private_ip_address?() click to toggle source

Is the Query text a private IP address?

# File lib/geocoder/query.rb, line 87
def private_ip_address?
  ip_address? && IpAddress.new(text).private?
end
reverse_geocode?() click to toggle source

Should reverse geocoding be performed for this query?

# File lib/geocoder/query.rb, line 112
def reverse_geocode?
  coordinates?
end
sanitized_text() click to toggle source
# File lib/geocoder/query.rb, line 18
def sanitized_text
  if coordinates?
    if text.is_a?(Array)
      text.join(',')
    else
      text.split(/\s*,\s*/).join(',')
    end
  else
    text
  end
end
to_s() click to toggle source
# File lib/geocoder/query.rb, line 14
def to_s
  text
end
url() click to toggle source
# File lib/geocoder/query.rb, line 44
def url
  lookup.query_url(self)
end