Class: Loopiator::Models::DnsRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/loopiator/models/dns_record.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ DnsRecord

Returns a new instance of DnsRecord.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/loopiator/models/dns_record.rb', line 8

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

Instance Attribute Details

#priorityObject

Returns the value of attribute priority.



6
7
8
# File 'lib/loopiator/models/dns_record.rb', line 6

def priority
  @priority
end

#rdataObject

Returns the value of attribute rdata.



6
7
8
# File 'lib/loopiator/models/dns_record.rb', line 6

def rdata
  @rdata
end

#record_idObject

Returns the value of attribute record_id.



6
7
8
# File 'lib/loopiator/models/dns_record.rb', line 6

def record_id
  @record_id
end

#ttlObject

Returns the value of attribute ttl.



6
7
8
# File 'lib/loopiator/models/dns_record.rb', line 6

def ttl
  @ttl
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/loopiator/models/dns_record.rb', line 6

def type
  @type
end

Instance Method Details

#to_hObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/loopiator/models/dns_record.rb', line 20

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