Class: Autometal::Geoip::Package
- Inherits:
-
Object
- Object
- Autometal::Geoip::Package
- Defined in:
- lib/geoip.rb
Overview
Extensible class that uses the Geoip binaries and data files to geolocate IPs and Hostnames.
To extend it to use a database, you will need to subclass Geoip::Package, define process_response, and self.data_file
See geoip/city.rb and geoip/organization.rb for extension examples
Direct Known Subclasses
Instance Attribute Summary collapse
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ip_or_domain) ⇒ Package
constructor
A new instance of Package.
- #lookup(ip_or_domain) ⇒ Object
- #process_response ⇒ Object
Constructor Details
#initialize(ip_or_domain) ⇒ Package
Returns a new instance of Package.
30 31 32 33 34 |
# File 'lib/geoip.rb', line 30 def initialize ip_or_domain return false unless self.class.installed? @response = self.lookup ip_or_domain process_response end |
Instance Attribute Details
#version ⇒ Object
Returns the value of attribute version.
29 30 31 |
# File 'lib/geoip.rb', line 29 def version @version end |
Class Method Details
.data_file ⇒ Object
40 41 42 |
# File 'lib/geoip.rb', line 40 def self.data_file end |
.installed? ⇒ Boolean
44 45 46 47 48 |
# File 'lib/geoip.rb', line 44 def self.installed? return false unless Geoip.bin_installed? return false unless File.exists? data_file true end |
Instance Method Details
#lookup(ip_or_domain) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/geoip.rb', line 50 def lookup ip_or_domain str = %x{ #{Geoip::BIN} -f #{self.class.data_file} #{ip_or_domain} } if RUBY_VERSION.to_f > 1.8 str.force_encoding("iso-8859-1") unless str.valid_encoding? end str end |
#process_response ⇒ Object
36 37 38 |
# File 'lib/geoip.rb', line 36 def process_response # deine this in the extension models end |