Module: IpV6Utils

Defined in:
lib/ruby-common/common/Ipv6Utils.rb

Class Method Summary collapse

Class Method Details

.abbreviate(ip_address) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby-common/common/Ipv6Utils.rb', line 14

def self.abbreviate(ip_address)
  begin
    ip = IPAddr.new(ip_address)

    unless ip.ipv6?
      raise ArgumentError, "Invalid address: #{ip_address}"
    end

    return ip.to_s
  rescue IPAddr::InvalidAddressError
    raise ArgumentError, "Invalid address: #{ip_address}"
  end
end

.validate(ip_address) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/ruby-common/common/Ipv6Utils.rb', line 5

def self.validate(ip_address)
  begin
    ip = IPAddr.new(ip_address)
    return ip.ipv6?
  rescue IPAddr::InvalidAddressError
    return false
  end
end