Sha256: f3c197f92ce2048839830cf809ca8060af9e805e4de2334a98ce64cb3751d9ca

Contents?: true

Size: 965 Bytes

Versions: 3

Compression:

Stored size: 965 Bytes

Contents

module Loopiator
  module Models
    
    #https://www.loopia.se/api/record_obj/
    class DnsRecord
      attr_accessor :record_id, :type, :ttl, :priority, :rdata
      
      def initialize(hash = nil)
        if hash && hash.is_a?(Hash) && !hash.empty?
          hash.symbolize_keys! 
        
          self.record_id    =   hash.fetch(:record_id, nil)
          self.type         =   hash.fetch(:type, "").to_s
          self.ttl          =   hash.fetch(:ttl, 3_600).to_i
          self.priority     =   hash.fetch(:priority, 0).to_i
          self.rdata        =   hash.fetch(:rdata, "").to_s
        end
      end
      
      def to_h
        data                =   {
          type:       self.type,
          ttl:        self.ttl,
          priority:   self.priority,
          rdata:      self.rdata
        }
        
        data[:record_id]    =   self.record_id if self.record_id
        
        return data
      end
      
    end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
loopiator-0.4.2 lib/loopiator/models/dns_record.rb
loopiator-0.4.1 lib/loopiator/models/dns_record.rb
loopiator-0.4.0 lib/loopiator/models/dns_record.rb