Class: IP::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/ip/address.rb

Overview

IP::Address - base class for IP::Address::IPv4 and IP::Address::IPv6

Direct Known Subclasses

IPv4, IPv6

Defined Under Namespace

Modules: Util Classes: IPv4, IPv6

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ip_addressObject (readonly)

This original IP Address you passed it, returned as a string.



10
11
12
# File 'lib/ip/address.rb', line 10

def ip_address
  @ip_address
end

#octetsObject (readonly)

This returns an Array of Integer which contains the octets of the IP, in descending order.



15
16
17
# File 'lib/ip/address.rb', line 15

def octets
  @octets
end

Instance Method Details

#[](num) ⇒ Object Also known as: octet

Returns an octet given the proper index. The octets returned are Integer types.



21
22
23
24
25
26
# File 'lib/ip/address.rb', line 21

def [](num)
  if @octets[num].nil?
    raise IP::BoundaryException.new("Invalid octet")
  end
  return @octets[num]
end

#packObject

Returns a 128-bit integer representing the address.



36
37
38
# File 'lib/ip/address.rb', line 36

def pack
  fail "This method is abstract."
end