Class: Nexpose::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose/test.rb

Class Method Summary collapse

Class Method Details

.new(xml_node) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nexpose/test.rb', line 3

def self.new(xml_node)
  content =
    # get first Paragraph or ContainerBlockElement that's a direct child of <test>
    if xml = xml_node.at_xpath('./Paragraph | ./ContainerBlockElement')
      # get all nested paragraph elements
      nested_paragraphs = xml.xpath('.//Paragraph')

      content = nested_paragraphs.children.map do |node|
        case node.name
        when 'text'
          node.text.strip
        when 'URLLink'
          node['LinkURL']
        end
      end.compact
      content.map(&:strip).reject(&:empty?).join("\n")
    else
      'n/a'
    end

  {
    id: xml_node.attributes['id'],
    status: xml_node.attributes['status'],
    content: content,
    port: xml_node.attributes['port'],
    protocol: xml_node.attributes['protocol']
  }
end