Class: Dnsruby::RR::MX

Inherits:
Dnsruby::RR show all
Defined in:
lib/dnsruby/resource/MX.rb

Overview

Class for DNS Mail Exchanger (MX) resource records. RFC 1035 Section 3.3.9

Constant Summary collapse

ClassValue =

:nodoc: all

nil
TypeValue =

:nodoc: all

Types::MX

Constants inherited from Dnsruby::RR

ClassInsensitiveTypes

Instance Attribute Summary collapse

Attributes inherited from Dnsruby::RR

#klass, #name, #rdata, #ttl, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Dnsruby::RR

#<=>, #==, #clone, create, #eql?, find_class, get_class, get_num, #hash, implemented_rrs, #init_defaults, new_from_data, new_from_hash, new_from_string, #rdlength, #sameRRset, #to_s

Instance Attribute Details

#exchangeObject

The name of this mail exchange.



27
28
29
# File 'lib/dnsruby/resource/MX.rb', line 27

def exchange
  @exchange
end

#preferenceObject

The preference for this mail exchange.



25
26
27
# File 'lib/dnsruby/resource/MX.rb', line 25

def preference
  @preference
end

Class Method Details

.decode_rdata(msg) ⇒ Object

:nodoc: all



62
63
64
65
66
# File 'lib/dnsruby/resource/MX.rb', line 62

def self.decode_rdata(msg) #:nodoc: all
  preference, = msg.get_unpack('n')
  exchange = msg.get_name
  return self.new([preference, exchange])
end

Instance Method Details

#encode_rdata(msg, canonical = false) ⇒ Object

:nodoc: all



57
58
59
60
# File 'lib/dnsruby/resource/MX.rb', line 57

def encode_rdata(msg, canonical=false) #:nodoc: all
  msg.put_pack('n', @preference, canonical)
  msg.put_name(@exchange, canonical)
end

#from_data(data) ⇒ Object

:nodoc: all



34
35
36
# File 'lib/dnsruby/resource/MX.rb', line 34

def from_data(data) #:nodoc: all
  @preference, @exchange = data
end

#from_hash(hash) ⇒ Object

:nodoc: all



29
30
31
32
# File 'lib/dnsruby/resource/MX.rb', line 29

def from_hash(hash) #:nodoc: all
  @preference = hash[:preference]
  @exchange = Name.create(hash[:exchange])
end

#from_string(input) ⇒ Object

:nodoc: all



38
39
40
41
42
43
44
45
46
47
# File 'lib/dnsruby/resource/MX.rb', line 38

def from_string(input) #:nodoc: all
  if (input.length > 0)
    names = input.split(" ")
    if(names.size != 2)
      raise DecodeError.new("MX record expects preference and domain")
    end
    @preference = names[0].to_i
    @exchange = Name.create(names[1])
  end
end

#rdata_to_stringObject

:nodoc: all



49
50
51
52
53
54
55
# File 'lib/dnsruby/resource/MX.rb', line 49

def rdata_to_string #:nodoc: all
  if (@preference!=nil)
    return "#{@preference} #{@exchange.to_s(true)}"
  else
    return ""
  end
end