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
-
.load(string, options = {}) ⇒ Object
Load RR string data and return an instance representing the RR.
Class Method Details
.load(string, options = {}) ⇒ Object
Load RR string data and return an instance representing the RR.
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, = {}) # 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, ) when 'AAAA' then AAAA.new.load(string, ) when 'CNAME' then CNAME.new.load(string, ) when 'HINFO' then HINFO.new.load(string, ) when 'MX' then MX.new.load(string, ) when 'NS' then NS.new.load(string, ) when 'PTR' then PTR.new.load(string, ) when 'SOA' then SOA.new.load(string, ) when 'SPF' then SPF.new.load(string, ) when 'SRV' then SRV.new.load(string, ) when 'TXT' then TXT.new.load(string, ) else raise 'Unknown RR Type' end end |