Guest User

Untitled

a guest
Jul 15th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. class Geolocator
  2.  
  3. DB = Rails.root.join('db/GeoIP.dat')
  4.  
  5. def initialize
  6. @geo_ip = GeoIP.new(DB)
  7. end
  8.  
  9. def locate(ip)
  10. _, _, _, country_code, _, _, _ = @geo_ip.country(ip)
  11. (country_code == "--") ? nil : country_code
  12. end
  13.  
  14. def self.locate(ip)
  15. self.new.locate(ip)
  16. end
  17.  
  18. end
Add Comment
Please, Sign In to add comment