Class: Dnsruby::Prefix
- Inherits:
-
Object
- Object
- Dnsruby::Prefix
- Defined in:
- lib/dnsruby/resource/APL.rb
Constant Summary collapse
- Regex =
%r{\A([!])?([12]):(.*)/(\d+)\z}
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#address_lenght ⇒ Object
readonly
Returns the value of attribute address_lenght.
-
#af ⇒ Object
readonly
Returns the value of attribute af.
-
#negative ⇒ Object
readonly
Returns the value of attribute negative.
-
#prefix_length ⇒ Object
readonly
Returns the value of attribute prefix_length.
Class Method Summary collapse
-
.create(prefix) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(af, prefix_length, negative, address_length, address) ⇒ Prefix
constructor
A new instance of Prefix.
-
#put_msg(msg) ⇒ Object
:nodoc: all.
- #to_s ⇒ Object
Constructor Details
#initialize(af, prefix_length, negative, address_length, address) ⇒ Prefix
Returns a new instance of Prefix.
34 35 36 37 38 39 40 41 42 |
# File 'lib/dnsruby/resource/APL.rb', line 34 def initialize(af, prefix_length, negative, address_length, address) @af = af @prefix_length = prefix_length @negative = negative @address_length = address_length @address = address @flag = address_length @flag |= 0x80 if @negative end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
4 5 6 |
# File 'lib/dnsruby/resource/APL.rb', line 4 def address @address end |
#address_lenght ⇒ Object (readonly)
Returns the value of attribute address_lenght.
4 5 6 |
# File 'lib/dnsruby/resource/APL.rb', line 4 def address_lenght @address_lenght end |
#af ⇒ Object (readonly)
Returns the value of attribute af.
4 5 6 |
# File 'lib/dnsruby/resource/APL.rb', line 4 def af @af end |
#negative ⇒ Object (readonly)
Returns the value of attribute negative.
4 5 6 |
# File 'lib/dnsruby/resource/APL.rb', line 4 def negative @negative end |
#prefix_length ⇒ Object (readonly)
Returns the value of attribute prefix_length.
4 5 6 |
# File 'lib/dnsruby/resource/APL.rb', line 4 def prefix_length @prefix_length end |
Class Method Details
.create(prefix) ⇒ Object
:nodoc:
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dnsruby/resource/APL.rb', line 6 def create(prefix) #:nodoc: unless md = Regex.match(prefix) raise ArgumentError.new('APL format error') end negative=md[1] af = md[2].to_i prefix_length = md[4].to_i case af when 1 if prefix_length > 32 || prefix_length < 0 raise ArgumentError.new('APL IPv4 prefix format error') end address = IPv4.create(md[3]) when 2 if prefix_length > 128 || prefix_length < 0 raise ArgumentError.new('APL IPv6 prefix format error') end address = IPv6.create(md[3]) else raise ArgumentError.new('APL address family error') end address_length = (prefix_length / 8.0).ceil Prefix.new(af, prefix_length, negative, address_length, address) end |
Instance Method Details
#put_msg(msg) ⇒ Object
:nodoc: all
48 49 50 51 |
# File 'lib/dnsruby/resource/APL.rb', line 48 def put_msg(msg) #:nodoc: all msg.put_pack('nCC',@af,@prefix_length,@flag) msg.put_bytes(@address.address[0,@address_length]) end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/dnsruby/resource/APL.rb', line 44 def to_s "#{@negative}#{@af}:#{@address}/#{@prefix_length}" end |