Class: Nessus::Parse

Inherits:
Object
  • Object
show all
Defined in:
lib/gemcache/ruby-nessus/ruby-nessus/parse.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}, &block) ⇒ Parse

Returns a new instance of Parse.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gemcache/ruby-nessus/ruby-nessus/parse.rb', line 14

def initialize(file, options={}, &block)
  @file = File.open(file)
  @version = options[:version]
  @xml = Nokogiri::XML.parse(@file.read)

  if @version
    case @version
      when 1
        block.call(Version1::XML.new(@xml)) if block
      when 2
        block.call(Version2::XML.new(@xml)) if block
      else
        raise "Error: Supported .Nessus Version are 1 and 2."
    end
  else
    if @xml.at('NessusClientData')
      block.call(Version1::XML.new(@xml)) if block
    elsif @xml.at('NessusClientData_v2')
      block.call(Version2::XML.new(@xml)) if block
    else
      raise "Error: Supported .Nessus Version are 1 and 2."
    end
  end

end