module IpAddresslike

Constants

ONES

Public Instance Methods

bitness_max(bitness) click to toggle source

Masks off all but the ‘bitness` most-significant-bits, filling with ones

@example /24 fills the last quad

IpAddress.new('1.2.3.4').bitness_min(24) # '1.2.3.255'
# File lib/gorillib/type/ip_address.rb, line 20
def bitness_max(bitness)
  raise ArgumentError, "IP addresses have only 32 bits (got #{bitness.inspect})" unless (0..32).include?(bitness)
  packed | (ONES >> bitness)
end
bitness_min(bitness) click to toggle source

Masks off all but the ‘bitness` most-significant-bits

@example /24 keeps only the first three quads

IpAddress.new('1.2.3.4').bitness_min(24) # '1.2.3.0'
# File lib/gorillib/type/ip_address.rb, line 9
def bitness_min(bitness)
  raise ArgumentError, "IP addresses have only 32 bits (got #{bitness.inspect})" unless (0..32).include?(bitness)
  lsbs = 32 - bitness
  (packed >> lsbs) << lsbs
end
to_hex() click to toggle source
# File lib/gorillib/type/ip_address.rb, line 25
def to_hex
  "%08x" % packed
end
to_s() click to toggle source
# File lib/gorillib/type/ip_address.rb, line 29
def to_s
  dotted
end