Class: Ipdb::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/ipdb/location.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location, timeout = 10) {|location| ... } ⇒ Location

Creates a new Location object.

Parameters:

  • node (Nokogiri::XML::Node)

    The XML node that contains the location information.

  • timeout (String) (defaults to: 10)

    The timeout for the location object.

Yields:

  • (location)

    If a block is given, it will be passed the newly created 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

#locationObject (readonly)

Location



7
8
9
# File 'lib/ipdb/location.rb', line 7

def location
  @location
end

Instance Method Details

#addressString

Return the Location address.

Returns:

  • (String)

    address



32
33
34
# File 'lib/ipdb/location.rb', line 32

def address
  @address = @xml.at('Ip').inner_text
end

#cityString

Return the Location City.

Returns:

  • (String)

    city



99
100
101
# File 'lib/ipdb/location.rb', line 99

def city
  @city = @xml.at('City').inner_text
end

#countryString

Return the Location Country.

Returns:

  • (String)

    country



72
73
74
# File 'lib/ipdb/location.rb', line 72

def country
  @country_name = @xml.at('CountryName').inner_text
end

#country_codeString

Return the Location Country Coce.

Returns:

  • (String)

    country_code



63
64
65
# File 'lib/ipdb/location.rb', line 63

def country_code
  @country_code = @xml.at('CountryCode').inner_text
end

#current_timeDateTime

TODO:

Make this method work correctly! =]

Return the Location Current Time.

Returns:

  • (DateTime)

    current_time



177
178
179
# File 'lib/ipdb/location.rb', line 177

def current_time
  (Time.now + timezone)
end

#dst_offsetInteger

Return the Location DST Offset. The gmtOffset/dstOffset fields names are a little misleading => dstOffset: offset to GMT at 1st July.

Returns:

  • (Integer)

    dst_offset

See Also:



166
167
168
# File 'lib/ipdb/location.rb', line 166

def dst_offset
  @dst_offset = @xml.at('Dstoffset').inner_text.to_i
end

#gmt_offsetInteger

Return the Location GMT Offset. The gmtOffset/dstOffset fields names are a little misleading => gmtOffset: offset to GMT at 1st January.

Returns:

  • (Integer)

    gmt_offset

See Also:



154
155
156
# File 'lib/ipdb/location.rb', line 154

def gmt_offset
  @gmt_offset = @xml.at('Gmtoffset').inner_text.to_i
end

#hostnameString

Return the Location hostname.

Returns:

  • (String)

    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

#latitudeFloat

Return the Location Latitude.

Returns:

  • (Float)

    latitude



120
121
122
# File 'lib/ipdb/location.rb', line 120

def latitude
  @latitude = @xml.at('Latitude').inner_text.to_f
end

#longitudeFloat

Return the Location Longitude.

Returns:

  • (Float)

    longitude



129
130
131
# File 'lib/ipdb/location.rb', line 129

def longitude
  @longitude = @xml.at('Longitude').inner_text.to_f
end

#regionString

Return the Location Region.

Returns:

  • (String)

    region



90
91
92
# File 'lib/ipdb/location.rb', line 90

def region
  @region_name = @xml.at('RegionName').inner_text
end

#region_codeString

Return the Location Region Code.

Returns:

  • (String)

    region_code



81
82
83
# File 'lib/ipdb/location.rb', line 81

def region_code
  @region_code = @xml.at('RegionCode').inner_text
end

#statusString

Return the Location status.

Returns:

  • (String)

    status



41
42
43
# File 'lib/ipdb/location.rb', line 41

def status
  @status = @xml.at('Status').inner_text
end

#time_zoneInteger Also known as: timezone

Return the Location Time Zone Offset.

Returns:

  • (Integer)

    time_zone

See Also:



141
142
143
# File 'lib/ipdb/location.rb', line 141

def time_zone
  @timezone = @xml.at('Timezone').inner_text.to_i
end

#to_sString

Return the Location as a string

Returns:

  • (String)

    location



186
187
188
# File 'lib/ipdb/location.rb', line 186

def to_s
  "#{address} #{hostname} #{country} #{region} #{city}"
end

#zip_codeInteger Also known as: zipcode

Return the Location Zip Code.

Returns:

  • (Integer)

    zip_code

See Also:



110
111
112
# File 'lib/ipdb/location.rb', line 110

def zip_code
  @zip_code = @xml.at('ZipPostalCode').inner_text.to_i
end