Class: IPRanger::IPAddress

Inherits:
IPAddr
  • Object
show all
Defined in:
lib/ip_ranger/ip_address.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_integer(i, family, mask = nil) ⇒ Object



6
7
8
9
10
11
# File 'lib/ip_ranger/ip_address.rb', line 6

def self.from_integer(i, family, mask = nil)
  address = IPAddr.new(i, family)
  address = address.mask(mask) if mask

  new(address)
end

Instance Method Details

#firstObject



33
34
35
# File 'lib/ip_ranger/ip_address.rb', line 33

def first
  to_range.first.to_i
end

#lastObject



37
38
39
# File 'lib/ip_ranger/ip_address.rb', line 37

def last
  to_range.last.to_i
end

#predObject



21
22
23
# File 'lib/ip_ranger/ip_address.rb', line 21

def pred
  self.class.new(IPAddr.new(to_i - 1, family))
end

#prefixlenObject



29
30
31
# File 'lib/ip_ranger/ip_address.rb', line 29

def prefixlen
  mask_addr.to_s(2).count('1')
end

#succObject



17
18
19
# File 'lib/ip_ranger/ip_address.rb', line 17

def succ
  self.class.new(super)
end

#to_cidrObject



25
26
27
# File 'lib/ip_ranger/ip_address.rb', line 25

def to_cidr
  "#{to_string}/#{prefixlen}"
end

#widthObject



13
14
15
# File 'lib/ip_ranger/ip_address.rb', line 13

def width
  ipv4? ? 32 : 128
end