Class Net::DNS::RR::Classes
In: lib/net/dns/rr/classes.rb
Parent: Object

This is an auxiliary class to hadle RR class field in a DNS packet.

Methods

default=   inspect   new   regexp   to_i   to_s   to_str   to_str   valid?  

Constants

Classes = { 'IN' => 1, # RFC 1035 'CH' => 3, # RFC 1035 'HS' => 4, # RFC 1035 'NONE' => 254, # RFC 2136 'ANY' => 255, # RFC 1035 }   An hash with the values of each RR class stored with the respective id number

Public Class methods

Be able to control the default class to assign when cls argument is nil. Default to IN

[Source]

# File lib/net/dns/rr/classes.rb, line 26
        def self.default=(str)
          if Classes.has_key? str
            @@default = Classes[str]
          else
            raise ClassArgumentError, "Unknown class #{str}"
          end
        end

Creates a new object representing an RR class. Performs some checks on the argument validity too. Il cls is nil, the default value is ANY or the one set with Classes.default=

[Source]

# File lib/net/dns/rr/classes.rb, line 70
        def initialize(cls)
          case cls
          when String
            # type in the form "A" or "NS"
            new_from_string(cls.upcase) 
          when Fixnum
            # type in numeric form
            new_from_num(cls) 
          when nil
            # default type, control with Classes.default=
            @str = Classes.invert[@@default] 
            @num = @@default
          else
            raise ClassArgumentError, "Wrong cls class: #{cls.class}"
          end
        end

Gives in output the keys from the Classes hash in a format suited for regexps

[Source]

# File lib/net/dns/rr/classes.rb, line 63
        def self.regexp
          Classes.keys.sort.join("|")
        end

Returns the class in string format, as "IN" or "CH", given the numeric value

[Source]

# File lib/net/dns/rr/classes.rb, line 48
        def self.to_str(cls)
          case cls
          when Fixnum
            if Classes.invert.has_key? cls
              return Classes.invert[cls]
            else
              raise ClassArgumentError, "Unknown class number #{cls}"
            end
          else
            raise ClassArgumentError, "Wrong cls class: #{cls.class}"
          end
        end

Checks whether cls is a valid RR class.

[Source]

# File lib/net/dns/rr/classes.rb, line 35
        def self.valid?(cls)
          case cls
          when String
            return Classes.has_key?(cls)
          when Fixnum
            return Classes.invert.has_key?(cls)
          else
            raise ClassArgumentError, "Wrong cls class: #{cls.class}"
          end
        end

Public Instance methods

Returns the class in number format (default for normal use)

[Source]

# File lib/net/dns/rr/classes.rb, line 117
        def inspect
          @num
        end

Returns the class in numeric format, usable by the pack methods for data transfers

[Source]

# File lib/net/dns/rr/classes.rb, line 129
        def to_i
          @num.to_i
        end

Returns the class in string format, i.d. "IN" or "CH" or such a string.

[Source]

# File lib/net/dns/rr/classes.rb, line 123
        def to_s
          @str
        end

Should be used only for testing purpouses

[Source]

# File lib/net/dns/rr/classes.rb, line 135
        def to_str
          @num.to_s
        end

[Validate]