Class: TinyDNS::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/tinydns/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Parser

Returns a new instance of Parser.



5
6
7
# File 'lib/tinydns/parser.rb', line 5

def initialize(io)
  @io = io
end

Instance Method Details

#parseObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tinydns/parser.rb', line 9

def parse
  @io.split("\n").collect do |line|
    unless line.strip.start_with? "#"
      type = line[0]
      name, value, ttl, other = line[1..-1].split(":")
      record = {:type => type, :name => name, :value => value, :ttl => ttl}
      record.merge!(:other => other) if other
      Record.new(record)
    end
  end.reject {|item| item == nil}
end