Class: Ipdb::Location
- Inherits:
-
Object
- Object
- Ipdb::Location
- Defined in:
- lib/ipdb/location.rb
Instance Attribute Summary (collapse)
-
- (Object) location
readonly
Location.
Instance Method Summary (collapse)
-
- (String) address
Return the Location address.
-
- (String) city
Return the Location City.
-
- (String) country
Return the Location Country.
-
- (String) country_code
Return the Location Country Coce.
-
- (DateTime) current_time
Return the Location Current Time.
-
- (Integer) dst_offset
Return the Location DST Offset.
-
- (Integer) gmt_offset
Return the Location GMT Offset.
-
- (String) hostname
Return the Location hostname.
-
- (Location) initialize(location, timeout = 10) {|location| ... }
constructor
Creates a new Location object.
-
- (Float) latitude
Return the Location Latitude.
-
- (Float) longitude
Return the Location Longitude.
-
- (String) region
Return the Location Region.
-
- (String) region_code
Return the Location Region Code.
-
- (String) status
Return the Location status.
-
- (Integer) time_zone
(also: #timezone)
Return the Location Time Zone Offset.
-
- (String) to_s
Return the Location as a string.
-
- (Integer) zip_code
(also: #zipcode)
Return the Location Zip Code.
Constructor Details
- (Location) initialize(location, timeout = 10) {|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
- (Object) location (readonly)
Location
7 8 9 |
# File 'lib/ipdb/location.rb', line 7 def location @location end |
Instance Method Details
- (String) address
Return the Location address.
32 33 34 |
# File 'lib/ipdb/location.rb', line 32 def address @address = @xml.at('Ip').inner_text end |
- (String) city
Return the Location City.
99 100 101 |
# File 'lib/ipdb/location.rb', line 99 def city @city = @xml.at('City').inner_text end |
- (String) country
Return the Location Country.
72 73 74 |
# File 'lib/ipdb/location.rb', line 72 def country @country_name = @xml.at('CountryName').inner_text end |
- (String) country_code
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 |
- (DateTime) current_time
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 |
- (Integer) dst_offset
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 |
- (Integer) gmt_offset
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 |
- (String) hostname
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 |
- (Float) latitude
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 |
- (Float) longitude
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 |
- (String) region
Return the Location Region.
90 91 92 |
# File 'lib/ipdb/location.rb', line 90 def region @region_name = @xml.at('RegionName').inner_text end |
- (String) region_code
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 |
- (String) status
Return the Location status.
41 42 43 |
# File 'lib/ipdb/location.rb', line 41 def status @status = @xml.at('Status').inner_text end |
- (Integer) time_zone 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 |
- (String) to_s
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 |
- (Integer) zip_code 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 |