Class: Dnsruby::Question
- Inherits:
-
Object
- Object
- Dnsruby::Question
- Defined in:
- lib/dnsruby/message/question.rb
Instance Attribute Summary collapse
-
#qclass ⇒ Object
(also: #zclass)
The Question class.
-
#qname ⇒ Object
(also: #zname)
The Question name.
-
#qtype ⇒ Object
(also: #ztype, #type)
The Question type.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(qname, qtype = :not_provided, qclass = :not_provided) ⇒ Question
constructor
Creates a question object from the domain, type, and class passed as arguments.
- #set_qname(qname, write_PTR_to_qtype_if_ip = true) ⇒ Object
-
#to_s ⇒ Object
Returns a string representation of the question record.
Constructor Details
#initialize(qname, qtype = :not_provided, qclass = :not_provided) ⇒ Question
Creates a question object from the domain, type, and class passed
as arguments.
If a String is passed in, a Name, IPv4 or IPv6 object is created.
If an IPv4 or IPv6 object is used then the type is set to PTR.
21 22 23 24 25 26 27 28 |
# File 'lib/dnsruby/message/question.rb', line 21 def initialize(qname, qtype = :not_provided, qclass = :not_provided) raise ArgumentError.new('qname must not be nil') if qname.nil? @qtype = (qtype == :not_provided) ? Types::A : Types.new(qtype) @qclass = (qclass == :not_provided) ? Classes::IN : Classes.new(qclass) set_qname(qname, qtype == :not_provided) end |
Instance Attribute Details
#qclass ⇒ Object Also known as: zclass
The Question class
13 14 15 |
# File 'lib/dnsruby/message/question.rb', line 13 def qclass @qclass end |
#qname ⇒ Object Also known as: zname
The Question name
9 10 11 |
# File 'lib/dnsruby/message/question.rb', line 9 def qname @qname end |
#qtype ⇒ Object Also known as: ztype, type
The Question type
11 12 13 |
# File 'lib/dnsruby/message/question.rb', line 11 def qtype @qtype end |
Instance Method Details
#==(other) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/dnsruby/message/question.rb', line 65 def ==(other) other.is_a?(Question) && self.qname == other.qname && self.qtype == other.qtype && self.qclass == Classes.new(other.qclass) end |
#set_qname(qname, write_PTR_to_qtype_if_ip = true) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dnsruby/message/question.rb', line 38 def set_qname(qname, write_PTR_to_qtype_if_ip = true) is_ipv4_addr_string = qname.is_a?(String) && IPv4::Regex.match(qname) is_ipv6_addr_string = qname.is_a?(String) && IPv6::Regex.match(qname) is_ip_addr_string = is_ipv4_addr_string || is_ipv6_addr_string is_ip_addr = [IPv4, IPv6].any? { |klass| qname.is_a?(klass) } if is_ipv4_addr_string @qname = IPv4.create(qname).to_name elsif is_ipv6_addr_string @qname = IPv6.create(qname).to_name else @qname = Name.create(qname) end # If the name looks like an IP address then do an appropriate # PTR query, unless the user specified the qtype if write_PTR_to_qtype_if_ip && (is_ip_addr || is_ip_addr_string) @qtype = Types.PTR end @qname.absolute = true end |
#to_s ⇒ Object
Returns a string representation of the question record.
73 74 75 |
# File 'lib/dnsruby/message/question.rb', line 73 def to_s "#{@qname}.\t#{@qclass.string}\t#{@qtype.string}" end |