Class: IPRanger::IPAddress
- Inherits:
-
IPAddr
- Object
- IPAddr
- IPRanger::IPAddress
- Defined in:
- lib/ip_ranger/ip_address.rb
Class Method Summary collapse
Instance Method Summary collapse
- #first ⇒ Object
- #last ⇒ Object
- #pred ⇒ Object
- #prefixlen ⇒ Object
- #succ ⇒ Object
- #to_cidr ⇒ Object
- #width ⇒ Object
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
#first ⇒ Object
33 34 35 |
# File 'lib/ip_ranger/ip_address.rb', line 33 def first to_range.first.to_i end |
#last ⇒ Object
37 38 39 |
# File 'lib/ip_ranger/ip_address.rb', line 37 def last to_range.last.to_i end |
#pred ⇒ Object
21 22 23 |
# File 'lib/ip_ranger/ip_address.rb', line 21 def pred self.class.new(IPAddr.new(to_i - 1, family)) end |
#prefixlen ⇒ Object
29 30 31 |
# File 'lib/ip_ranger/ip_address.rb', line 29 def prefixlen mask_addr.to_s(2).count('1') end |
#succ ⇒ Object
17 18 19 |
# File 'lib/ip_ranger/ip_address.rb', line 17 def succ self.class.new(super) end |
#to_cidr ⇒ Object
25 26 27 |
# File 'lib/ip_ranger/ip_address.rb', line 25 def to_cidr "#{to_string}/#{prefixlen}" end |
#width ⇒ Object
13 14 15 |
# File 'lib/ip_ranger/ip_address.rb', line 13 def width ipv4? ? 32 : 128 end |