Class: Ipdb::Location
- Inherits:
-
Object
- Object
- Ipdb::Location
- Defined in:
- lib/ipdb/location.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Location.
Instance Method Summary collapse
-
#address ⇒ String
Return the Location address.
-
#city ⇒ String
Return the Location City.
-
#country ⇒ String
Return the Location Country.
-
#country_code ⇒ String
Return the Location Country Coce.
-
#current_time ⇒ DateTime
Return the Location Current Time.
-
#dst_offset ⇒ Integer
Return the Location DST Offset.
-
#gmt_offset ⇒ Integer
Return the Location GMT Offset.
-
#hostname ⇒ String
Return the Location hostname.
-
#initialize(location, timeout = 10) {|location| ... } ⇒ Location
constructor
Creates a new Location object.
-
#latitude ⇒ Float
Return the Location Latitude.
-
#longitude ⇒ Float
Return the Location Longitude.
-
#region ⇒ String
Return the Location Region.
-
#region_code ⇒ String
Return the Location Region Code.
-
#status ⇒ String
Return the Location status.
-
#time_zone ⇒ Integer
(also: #timezone)
Return the Location Time Zone Offset.
-
#to_s ⇒ String
Return the Location as a string.
-
#zip_code ⇒ Integer
(also: #zipcode)
Return the Location Zip Code.
Constructor Details
#initialize(location, timeout = 10) {|location| ... } ⇒ Location
Creates a new Location object.
22 23 24 25 |
# File 'lib/ipdb/location.rb', line 22 def initialize(location, timeout=10) @xml = location @timeout = timeout end |
Instance Attribute Details
#location ⇒ Object (readonly)
Location
7 8 9 |
# File 'lib/ipdb/location.rb', line 7 def location @location end |
Instance Method Details
#address ⇒ String
Return the Location address.
32 33 34 |
# File 'lib/ipdb/location.rb', line 32 def address @address = @xml.at('Ip').inner_text end |
#city ⇒ String
Return the Location City.
99 100 101 |
# File 'lib/ipdb/location.rb', line 99 def city @city = @xml.at('City').inner_text end |
#country ⇒ String
Return the Location Country.
72 73 74 |
# File 'lib/ipdb/location.rb', line 72 def country @country_name = @xml.at('CountryName').inner_text end |
#country_code ⇒ String
Return the Location Country Coce.
63 64 65 |
# File 'lib/ipdb/location.rb', line 63 def country_code @country_code = @xml.at('CountryCode').inner_text end |
#current_time ⇒ DateTime
Make this method work correctly! =]
Return the Location Current Time.
177 178 179 |
# File 'lib/ipdb/location.rb', line 177 def current_time (Time.now + timezone) end |
#dst_offset ⇒ Integer
Return the Location DST Offset. The gmtOffset/dstOffset fields names are a little misleading => dstOffset: offset to GMT at 1st July.
166 167 168 |
# File 'lib/ipdb/location.rb', line 166 def dst_offset @dst_offset = @xml.at('Dstoffset').inner_text.to_i end |
#gmt_offset ⇒ Integer
Return the Location GMT Offset. The gmtOffset/dstOffset fields names are a little misleading => gmtOffset: offset to GMT at 1st January.
154 155 156 |
# File 'lib/ipdb/location.rb', line 154 def gmt_offset @gmt_offset = @xml.at('Gmtoffset').inner_text.to_i end |
#hostname ⇒ String
Return the Location hostname.
50 51 52 53 54 55 56 |
# File 'lib/ipdb/location.rb', line 50 def hostname Timeout::timeout(@timeout) do @hostname = Resolv.getname(address) end rescue Timeout::Error rescue end |
#latitude ⇒ Float
Return the Location Latitude.
120 121 122 |
# File 'lib/ipdb/location.rb', line 120 def latitude @latitude = @xml.at('Latitude').inner_text.to_f end |
#longitude ⇒ Float
Return the Location Longitude.
129 130 131 |
# File 'lib/ipdb/location.rb', line 129 def longitude @longitude = @xml.at('Longitude').inner_text.to_f end |
#region ⇒ String
Return the Location Region.
90 91 92 |
# File 'lib/ipdb/location.rb', line 90 def region @region_name = @xml.at('RegionName').inner_text end |
#region_code ⇒ String
Return the Location Region Code.
81 82 83 |
# File 'lib/ipdb/location.rb', line 81 def region_code @region_code = @xml.at('RegionCode').inner_text end |
#status ⇒ String
Return the Location status.
41 42 43 |
# File 'lib/ipdb/location.rb', line 41 def status @status = @xml.at('Status').inner_text end |
#time_zone ⇒ Integer Also known as: timezone
Return the Location Time Zone Offset.
141 142 143 |
# File 'lib/ipdb/location.rb', line 141 def time_zone @timezone = @xml.at('Timezone').inner_text.to_i end |
#to_s ⇒ String
Return the Location as a string
186 187 188 |
# File 'lib/ipdb/location.rb', line 186 def to_s "#{address} #{hostname} #{country} #{region} #{city}" end |
#zip_code ⇒ Integer Also known as: zipcode
Return the Location Zip Code.
110 111 112 |
# File 'lib/ipdb/location.rb', line 110 def zip_code @zip_code = @xml.at('ZipPostalCode').inner_text.to_i end |