Class: GeoLocatorRecord
- Inherits:
-
Object
- Object
- GeoLocatorRecord
- Defined in:
- lib/GeoLocator.rb
Instance Attribute Summary collapse
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#countryCode ⇒ Object
readonly
Returns the value of attribute countryCode.
-
#latitude ⇒ Object
readonly
Returns the value of attribute latitude.
-
#longitude ⇒ Object
readonly
Returns the value of attribute longitude.
-
#timeStamp ⇒ Object
Returns the value of attribute timeStamp.
Instance Method Summary collapse
-
#initialize ⇒ GeoLocatorRecord
constructor
A new instance of GeoLocatorRecord.
- #resolve(ip) ⇒ Object
Constructor Details
#initialize ⇒ GeoLocatorRecord
Returns a new instance of GeoLocatorRecord.
20 21 22 23 24 25 26 27 |
# File 'lib/GeoLocator.rb', line 20 def initialize @country = nil @countryCode = nil @city = nil @latitude = nil @longitude = nil @timeStamp = nil end |
Instance Attribute Details
#city ⇒ Object (readonly)
Returns the value of attribute city.
17 18 19 |
# File 'lib/GeoLocator.rb', line 17 def city @city end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
17 18 19 |
# File 'lib/GeoLocator.rb', line 17 def country @country end |
#countryCode ⇒ Object (readonly)
Returns the value of attribute countryCode.
17 18 19 |
# File 'lib/GeoLocator.rb', line 17 def countryCode @countryCode end |
#latitude ⇒ Object (readonly)
Returns the value of attribute latitude.
17 18 19 |
# File 'lib/GeoLocator.rb', line 17 def latitude @latitude end |
#longitude ⇒ Object (readonly)
Returns the value of attribute longitude.
17 18 19 |
# File 'lib/GeoLocator.rb', line 17 def longitude @longitude end |
#timeStamp ⇒ Object
Returns the value of attribute timeStamp.
18 19 20 |
# File 'lib/GeoLocator.rb', line 18 def timeStamp @timeStamp end |
Instance Method Details
#resolve(ip) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/GeoLocator.rb', line 29 def resolve(ip) begin http = Net::HTTP.new($globals.getSetting('GeolocHost'), $globals.getSetting('GeolocPort')) resp = http.get("/rough.php?ip=#{ip}&position=true", nil) # This is how the data string should look like: # data = <<EOS # Country: GERMANY # Country Code: DE # City: Albstadt # Latitude: 48.25 # Longitude: 9.0167 # Guessed: false # EOS resp.body.scan(/(.*):\s+(.*)\n/) do |tokens| tokens[1].gsub!(/\|/, '') case tokens[0] when 'Country' @country = tokens[1] when 'Country Code' @countryCode = tokens[1] when 'City' @city = tokens[1] when 'Latitude' val = tokens[1].to_f @latitude = val if val != 0 && val > -90 && val < 90 when 'Longitude' val = tokens[1].to_f @longitude = val if val != 0 && val >= -180 && val <= 180 else end end rescue return false end @timeStamp = Time.now() return true end |