Class: Spcap::IPAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/spcap/ipaddress.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ IPAddress

Returns a new instance of IPAddress.



5
6
7
# File 'lib/spcap/ipaddress.rb', line 5

def initialize(address)
  @address = address
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



3
4
5
# File 'lib/spcap/ipaddress.rb', line 3

def address
  @address
end

Instance Method Details

#<=>(other) ⇒ Object

Return true if two addresses are the same address.



10
11
12
# File 'lib/spcap/ipaddress.rb', line 10

def <=>(other)
  @address <=> other.address
end

#==(other) ⇒ Object

Return true if two addresses are the same address.



15
16
17
# File 'lib/spcap/ipaddress.rb', line 15

def ==(other)
  @address == other.address
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


19
# File 'lib/spcap/ipaddress.rb', line 19

def eql?(other) ; self == other ; end

#hashObject



21
22
23
# File 'lib/spcap/ipaddress.rb', line 21

def hash
  @address.hash
end

#hostnameObject

Return host name correspond to this address.



26
27
28
29
# File 'lib/spcap/ipaddress.rb', line 26

def hostname
  # Not yet implemented
  to_num_s
end

#to_iObject

Return the value of IP address as integer.



32
33
34
# File 'lib/spcap/ipaddress.rb', line 32

def to_i
  @address.unpackt("N").first
end

#to_num_sObject

Return numerical string representation



38
39
40
# File 'lib/spcap/ipaddress.rb', line 38

def to_num_s
  @address.unpack("CCCC").join('.')
end

#to_sObject



42
43
44
# File 'lib/spcap/ipaddress.rb', line 42

def to_s
  to_num_s
end