Class: RightSupport::Net::IPNet

Inherits:
IPAddr
  • Object
show all
Defined in:
lib/right_support/net/dns.rb

Overview

IPAddr does not support returning a block of addresses in CIDR notation.

Instance Method Summary collapse

Instance Method Details

#cidr_blockObject



31
32
33
34
# File 'lib/right_support/net/dns.rb', line 31

def cidr_block
  # Ruby Math:: does not have a log2() function :(
  cidr_block = 32 - (Math.log(self.to_range.count) / Math.log(2)).to_i
end

#to_cidrObject

Don’t want to override to_s here since we also use this during URI transformation and need a way to get the raw dotted-quad address



40
41
42
# File 'lib/right_support/net/dns.rb', line 40

def to_cidr
  "#{self.to_s}/#{self.cidr_block}"
end