module Geolocalise

Constants

VERSION

Public Class Methods

get_city(location) click to toggle source
# File lib/geolocalise.rb, line 5
def self.get_city(location)
  if (location =~ /[[:digit:]]/) == nil
    Geocoder.search(location).first.city
  else
    check_geo_cords(location) ? Geocoder.search(location).first.city : nil
  end
end
get_country(location) click to toggle source
# File lib/geolocalise.rb, line 13
def self.get_country(location)
  if (location =~ /[[:digit:]]/) == nil
    Geocoder.search(location).first.country
  else
    check_geo_cords(location) ? Geocoder.search(location).first.country : nil
  end
end
get_country_code(location) click to toggle source
# File lib/geolocalise.rb, line 29
def self.get_country_code(location)
  if (location =~ /[[:digit:]]/) == nil
    Geocoder.search(location).first.country_code
  else
    check_geo_cords(location) ? Geocoder.search(location).first.country_code : nil
  end
end
get_postal_code(location) click to toggle source
# File lib/geolocalise.rb, line 37
def self.get_postal_code(location)
  if (location =~ /[[:digit:]]/) == nil
    Geocoder.search(Geocoder.coordinates(location).map(&:inspect).join(',')).first.postal_code
  else
    check_geo_cords(location) ? Geocoder.search(location).first.postal_code : nil
  end
end
get_state(location) click to toggle source
# File lib/geolocalise.rb, line 21
def self.get_state(location)
  if (location =~ /[[:digit:]]/) == nil
    Geocoder.search(location).first.state
  else
    check_geo_cords(location) ? Geocoder.search(location).first.state : nil
  end
end

Private Class Methods

check_geo_cords(location) click to toggle source
# File lib/geolocalise.rb, line 47
def self.check_geo_cords(location)
  latitude, longitude = location.split(',')[0], location.split(',')[1]
  if latitude.to_i >= -90 and latitude.to_i <= 90 and (latitude =~ /[[:alpha:]]/) == nil
     if longitude.to_i >= -180 and longitude.to_i <= 180 and (longitude =~ /[[:alpha:]]/) == nil
       true
     else
       false
     end
  else
    false
  end
end