abstract struct IP::Block

Included Modules

Direct Known Subclasses

Defined in:

ip/block.cr
ip/block.cr

Constructors

Instance Method Summary

Constructor Detail

def self.[](string : String) : self #

Constructs a new IP::Block by interpreting the contents of a given String.

Expects a definition in CIDR notation similar to [0-255].[0-255].[0-255].[0-255]/[0-32], XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/[0-128], or XXXX:XXXX::XXXX:XXXX:XXXX/[0-128].

Raises: MalformedError when the input is malformed.


[View source]
def self.[]?(string : String) : self? #

Constructs a new IP::Block by interpreting the contents of a given String.

Expects a definition in CIDR notation similar to [0-255].[0-255].[0-255].[0-255]/[0-32], XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/[0-128], or XXXX:XXXX::XXXX:XXXX:XXXX/[0-128].

Returns nil when the input is malformed.


[View source]
def self.ipv4(string : String) : self #

Constructs a new IPv4 IP::Block by interpreting the contents of a given String.

Expects a definition in CIDR notation similar to [0-255].[0-255].[0-255].[0-255]/[0-32].

Raises: MalformedError when the input is malformed.


[View source]
def self.ipv4?(string : String) : self? #

Constructs a new IPv4 IP::Block by interpreting the contents of a given String.

Expects a definition in CIDR notation similar to [0-255].[0-255].[0-255].[0-255]/[0-32].

Returns nil when the input is malformed.


[View source]
def self.ipv6(string : String) : self #

Constructs a new IPv6 IP::Block by interpreting the contents of a given String.

Expects a definition in CIDR notation similar to XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/[0-128], or XXXX:XXXX::XXXX:XXXX:XXXX/[0-128].

Raises: MalformedError when the input is malformed.


[View source]
def self.ipv6?(string : String) : self? #

Constructs a new IPv6 IP::Block by interpreting the contents of a given String.

Expects a definition in CIDR notation similar to XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/[0-128], or XXXX:XXXX::XXXX:XXXX:XXXX/[0-128].

Returns nil when the input is malformed.


[View source]
def self.loopback_ipv4 : self #

Constructs a IP::Block:IPv4 representing the IPv4 loopback block.


[View source]
def self.loopback_ipv6 : self #

Constructs a IP::Block:IPv4 representing the IPv4 loopback block.


[View source]
def self.new(address : IP::Address, block : Int) : self? #

Constructs a new IP::Block from an address and block size.

Raises: MalformedError when the input is malformed.


[View source]
def self.new(string : String) : self #

Constructs a new IP::Block by interpreting the contents of a given String.

Expects a definition in CIDR notation similar to [0-255].[0-255].[0-255].[0-255]/[0-32], XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/[0-128], or XXXX:XXXX::XXXX:XXXX:XXXX/[0-128].

Raises: MalformedError when the input is malformed.


[View source]
def self.new?(address : IP::Address, block : Int) : self? #

Constructs a new IP::Block from an address and block size.

Raises: MalformedError when the input is malformed.


[View source]
def self.new?(string : String) : self? #

Constructs a new IP::Block by interpreting the contents of a given String.

Expects a definition in CIDR notation similar to [0-255].[0-255].[0-255].[0-255]/[0-32], XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/[0-128], or XXXX:XXXX::XXXX:XXXX:XXXX/[0-128].

Returns nil when the input is malformed.


[View source]

Instance Method Detail

def <(other : IP::Block) #

Compares this block to other returning true if the other block falls before the block.


[View source]
def <=(other : IP::Block) #

Compares this block to other returning true if the other block falls before or inside the block.


[View source]
def <=>(other : IP::Block) : Int #

Compares this block with the other block, returning -1, 0 or +1 depending if the block is less than, inclusive of, or greater than the other block.

Note: This is slightly different then the comparitors due to the added complexity of a range of values. This is effective for ordering, not comparing inclusivity. As such this object does not include Comparable for IP::Blocks and the comparative operators are added manually.


[View source]
def <=>(other : IP::Address) : Int #

Compares this block with address, returning -1, 0 or +1 depending if the block is less than, inclusive of, or greater than the other address.


[View source]
def ==(other : IP::Block) #

Compares this block to other returning true if the other block is equal to the receiver.


[View source]
def >(other : IP::Block) #

Compares this block to other returning true if the other block falls after the block.


[View source]
def >=(other : IP::Block) #

Compares this block to other returning true if the other block falls after or inside the block.


[View source]
abstract def address #

Returns the address component of the block which is also the first address.


[View source]
def adjacent?(other : IP::Address) : Bool #

Returns a Bool indicating if the receiver is 'adjacent' to other. That is to say the receiver is immidiatly beside, but not intersecting other.


[View source]
def adjacent?(other : IP::Block) : Bool #

Returns a Bool indicating if the receiver is 'adjacent' to other. That is to say the receiver is immidiatly beside, but not intersecting other.


[View source]
abstract def block #

Returns 'block' size in the form aof 2^x, x being the 'size'.


[View source]
def covers?(other : IP::Address) : Bool #

Returns a Bool indicating if the receiver 'covers' other. That is to say the receiver completely includes other.


[View source]
def covers?(other : IP::Block) : Bool #

Returns a Bool indicating if the receiver 'covers' other. That is to say the receiver completely includes other.


[View source]
def each(&block : IP::Address -> Nil) : Nil #

Yield each address to the block.


[View source]
def first : IP::Address #

Returns the first address in the block.


[View source]
def hash(hasher) #

See Object#hash(hasher)


[View source]
def includes?(other : IP::Address) : Bool #

Returns a Bool indicating if the receiver 'includes' the other address.


[View source]
def inspect(io : IO) : Nil #

Appends a type-specified presentation representation of the block to the given IO.


[View source]
def intersects?(other : IP::Block) : Bool #

Returns a Bool indicating if the receiver 'intersects' other. That is to say the receiver partially includes other.


[View source]
def intersects?(other : IP::Address) : Bool #

Returns a Bool indicating if the receiver 'intersects' other. That is to say the receiver partially includes other.


[View source]
def ipv4? : Bool #

Informs if the block is IPv4 or not.


[View source]
def ipv6? : Bool #

Informs if the block is IPv6 or not.


[View source]
def last : IP::Address #

Returns the last address in the block.


[View source]
def mask : IP::Address #

Returns the blocks mask.


[View source]
def single_address? : Bool #

Informs if the block is a single address or not.


[View source]
abstract def size #

Returns the size of the block in terms of number of addresses.


[View source]
def to_s(io : IO) : Nil #

Appends the presentation representation of the block to the given IO.


[View source]