Class: RedZone::Record
- Inherits:
-
Object
- Object
- RedZone::Record
- Defined in:
- lib/redzone/record.rb
Overview
DNS Record
Instance Method Summary collapse
-
#initialize(record) ⇒ Record
constructor
Returns a new instance of a domain record.
-
#to_s ⇒ String
Returns the domain record as a string to be written in the zone file.
Constructor Details
#initialize(record) ⇒ Record
Returns a new instance of a domain record
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/redzone/record.rb', line 13 def initialize(record) raise ArgumentError, ':name is required' unless record.has_key?(:name) raise ArgumentError, ':type is required' unless record.has_key?(:type) raise ArgumentError, ':data is required' unless record.has_key?(:data) @name = record[:name] @class = record[:class] || 'IN' @type = record[:type] if record.has_key?(:ttl) and not record[:ttl].nil? @ttl = Lifetime.new(record[:ttl]).seconds end @data = record[:data] if @type == "TXT" @data = '"%s"' % [@data.gsub(/^\s*"?|"?\s*$/,'').gsub(/\n/,'')] end if record.has_key?(:comment) and not record[:comment].nil? @comment = " ; %s" % [record[:comment]] end end |
Instance Method Details
#to_s ⇒ String
Returns the domain record as a string to be written in the zone file
33 34 35 |
# File 'lib/redzone/record.rb', line 33 def to_s "%-20s %-8s %s %-8s %-20s%s\n" % [@name, @ttl, @class, @type, @data, @comment || ''] end |