Class: Latte::Query

Inherits:
Object show all
Defined in:
lib/latte/query.rb

Defined Under Namespace

Classes: QueryHeader, QueryRequest

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object



102
103
104
105
106
# File 'lib/latte/query.rb', line 102

def method_missing *args
  result = parsed_record.send *args
  return result.value if result.respond_to? :value
  result
end

Instance Method Details

#build_recordObject



93
94
95
96
97
98
99
100
# File 'lib/latte/query.rb', line 93

def build_record
  case parsed_header.qr.value
  when 0
    QueryRequest.read raw_query
  else
    raise "Unhandled QR value: #{parsed_header.qr.value}"
  end
end

#headerObject



108
109
110
111
112
# File 'lib/latte/query.rb', line 108

def header
  "ID=#{id} QR=#{qr} TC=#{tc} RD=#{rd} RA=#{ra} Z=#{z} " + \
  "RCODE=#{rcode} QDCOUNT=#{qdcount} ANCOUNT=#{ancount} " + \
  "NSCOUNT=#{nscount} ARCOUNT=#{arcount}"
end

#human_qnameObject



114
115
116
117
118
119
# File 'lib/latte/query.rb', line 114

def human_qname
  value = parsed_record.qname.value.dup
  value.gsub! /^[\x00-\x1f]/, ''
  value.gsub! /[\x00-\x1f]/, '.'
  value + '.'
end

#queryObject



121
122
123
# File 'lib/latte/query.rb', line 121

def query
  "QNAME=#{human_qname} QTYPE=#{qtype} QCLASS=#{qclass}"
end

#to_sObject



125
126
127
# File 'lib/latte/query.rb', line 125

def to_s
  [ header, query ].join " "
end