Module: DNS::Zone::RR

Defined in:
lib/dns/zone/rr.rb

Overview

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

Defined Under Namespace

Classes: A, AAAA, CNAME, HINFO, MX, NS, PTR, Record, SOA, SPF, SRV, TXT

Constant Summary collapse

REGEX_TTL =
/\d+[wdmhs]?/i
REGEX_KLASS =
/(?<klass>IN)?/i
REGEX_TYPE =
/(?<type>A|AAAA|CNAME|HINFO|MX|NS|SOA|SPF|SRV|TXT|PTR)\s{1}/i
REGEX_RR =
/^(?<label>\S+|\s{1})\s*(?<ttl>#{REGEX_TTL})?\s*#{REGEX_KLASS}\s*#{REGEX_TYPE}\s*(?<rdata>[\s\S]*)$/i
REGEX_DOMAINNAME =
/\S+\./i
REGEX_STRING =
/((?:[^"\\]+|\\.)*)/

Class Method Summary collapse

Class Method Details

.load(string, options = {}) ⇒ Object

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

Parameters:

  • string (String)

    RR ASCII string data

  • options (Hash) (defaults to: {})

    additional data required to correctly parse a ‘whole’ zone

Options Hash (options):

  • :last_label (String)

    The last label used by the previous RR

Returns:

  • (Object)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dns/zone/rr.rb', line 21

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 'CNAME' then CNAME.new.load(string, options)
  when 'HINFO' then HINFO.new.load(string, options)
  when 'MX' then MX.new.load(string, options)
  when 'NS' then NS.new.load(string, options)
  when 'PTR' then PTR.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 'TXT' then TXT.new.load(string, options)
  else
    raise 'Unknown RR Type'          
  end
end