Parent

Net::DNS::RR::Classes

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

Constants

Classes

An hash with the values of each RR class stored with the respective id number

Public Class Methods

default=(str) click to toggle source

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

# 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
new(cls) click to toggle source

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=

# 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
regexp() click to toggle source

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

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

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

# 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
valid?(cls) click to toggle source

Checks whether cls is a valid RR class.

# 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

inspect() click to toggle source

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

# File lib/net/dns/rr/classes.rb, line 117
def inspect
  @num
end
to_i() click to toggle source

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

# File lib/net/dns/rr/classes.rb, line 129
def to_i
  @num.to_i
end
to_s() click to toggle source

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

# File lib/net/dns/rr/classes.rb, line 123
def to_s
  @str
end
to_str() click to toggle source

Should be used only for testing purpouses

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.