Module: WorldFlags::Helper::Geo
- Defined in:
- lib/world_flags/helper/geo.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.country_code_from_ip(ip = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/world_flags/helper/geo.rb', line 6 def self.country_code_from_ip ip = nil ip ||= request.remote_ip raise WorldFlags::GeoIPError, "IP address #{ip} is a localhost address" if local_ip?(ip) # puts "find country code for ip: #{ip}" if debug? @geoip ||= ::GeoIP.new WorldFlags.geo_ip_db_path country = @geoip.country(ip) return country[2] unless country.nil? rescue Exception => e raise WorldFlags::GeoIPError, "No country code could be found for IP: #{ip} - #{e}" end |
.debug? ⇒ Boolean
23 24 25 |
# File 'lib/world_flags/helper/geo.rb', line 23 def self.debug? WorldFlags.debug? end |
.local_ip?(ip) ⇒ Boolean
19 20 21 |
# File 'lib/world_flags/helper/geo.rb', line 19 def self.local_ip? ip WorldFlags.localhost_list.include?(ip) end |
Instance Method Details
#country_code_from_ip(ip = nil) ⇒ Object
27 28 29 |
# File 'lib/world_flags/helper/geo.rb', line 27 def country_code_from_ip ip = nil WorldFlags::Helper::Geo.country_code_from_ip ip end |