module DNS::Zone::RR

The module containes resource record types supported by this gem. The #{load} method will convert RR string data into a Ruby class.

Constants

REGEX_CHARACTER_STRING
REGEX_DOMAINNAME
REGEX_KLASS
REGEX_RR
REGEX_STRING
REGEX_TTL
REGEX_TYPE

Public Class Methods

load(string, options = {}) click to toggle source

Load RR string data and return an instance representing the RR.

@param string [String] RR ASCII string data @param options [Hash] additional data required to correctly parse a ‘whole’ zone @option options [String] :last_label The last label used by the previous RR @return [Object]

# File lib/dns/zone/rr.rb, line 24
def self.load(string, options = {})
  # strip comments, unless its escaped.
  # skip semicolons within "quote segments" (TXT records)
  string.gsub!(/((?<!\\);)(?=(?:[^"]|"[^"]*")*$).*/o, "")

  captures = string.match(REGEX_RR)
  return nil unless captures

  case captures[:type]
  when 'A'           then A.new.load(string, options)
  when 'AAAA'        then AAAA.new.load(string, options)
  when 'CDNSKEY'     then CDNSKEY.new.load(string, options)
  when 'CDS'         then CDS.new.load(string, options)
  when 'CNAME'       then CNAME.new.load(string, options)
  when 'DLV'         then DLV.new.load(string, options)
  when 'DNSKEY'      then DNSKEY.new.load(string, options)
  when 'DS'          then DS.new.load(string, options)
  when 'HINFO'       then HINFO.new.load(string, options)
  when 'MX'          then MX.new.load(string, options)
  when 'NAPTR'       then NAPTR.new.load(string, options)
  when 'NS'          then NS.new.load(string, options)
  when 'NSEC'        then NSEC.new.load(string, options)
  when 'NSEC3'       then NSEC3.new.load(string, options)
  when 'NSEC3PARAM'  then NSEC3PARAM.new.load(string, options)
  when 'PTR'         then PTR.new.load(string, options)
  when 'RRSIG'       then RRSIG.new.load(string, options)
  when 'SOA'         then SOA.new.load(string, options)
  when 'SPF'         then SPF.new.load(string, options)
  when 'SRV'         then SRV.new.load(string, options)
  when 'SSHFP'       then SSHFP.new.load(string, options)
  when 'TXT'         then TXT.new.load(string, options)
  else
    raise 'Unknown or unsupported RR Type'          
  end
end