Class: EnfCli::IPV6Cidr

Inherits:
Object
  • Object
show all
Defined in:
lib/enfcli.rb

Instance Method Summary collapse

Constructor Details

#initialize(ipv6cidr) ⇒ IPV6Cidr

Returns a new instance of IPV6Cidr.

Raises:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/enfcli.rb', line 82

def initialize(ipv6cidr)
  # split on /
  tokens = ipv6cidr.split("/")

  # raise exception if not cidr format
  raise EnfCli::ERROR, "#{ipv6cidr} is not a valid CIDR notation." unless tokens.length == 2

  # store in prefix/len
  @prefix = EnfCli::IPV6.new tokens[0]
  @len = tokens[1].to_i

  # raise if len is not 0
  raise EnfCli::ERROR, "#{ipv6cidr} is not a valid CIDR notation." unless len > 2
end

Instance Method Details

#prefix_bytesObject



97
98
99
# File 'lib/enfcli.rb', line 97

def prefix_bytes
  @prefix.hton
end

#prefix_lenObject



101
102
103
# File 'lib/enfcli.rb', line 101

def prefix_len
  @len
end

#to_sObject



105
106
107
# File 'lib/enfcli.rb', line 105

def to_s
  "#{@prefix.to_s}/#{@len}"
end