I want to intercept DNS queries and use the results for couple tests

i am trying to build a RBL\DRBL like server but not for blacklists.
i want the dns server to be a forwarder dns server that will have a
special txt response per ip\domain with some data structure i have.

i have seen a bit about RUBYDNS and it seems like a very good solution
for a dns server\forwarder.
the problem is that i kind of lost it somewhere how to get from a the
answer the data i need?
it seems like the answer is a ‘resolve’ class or something like that but
i’m not sure what methods to use to get the response.

this is the basic forwarder server:

require ‘rubygems’
require ‘rubydns’

$R = Resolv::DNS.new

RubyDNS::run_server do
Name = Resolv::DNS::Name
IN = Resolv::DNS::Resource::IN

 # Default DNS handler
 otherwise do |transaction|
     logger.info "Passing DNS request upstream..."

#here i want to get the transaction and tear it apart for query and
#what i need is to extract the request domain and A + AAAA records and
the cache period for the response items.
#i dont care about the additional and authority sections. just the
#then i am sending them to another method for some checks.