Class: Risu::Parsers::Nexpose::NexposeDocument
- Inherits:
-
Object
- Object
- Risu::Parsers::Nexpose::NexposeDocument
- Defined in:
- lib/risu/parsers/nexpose/nexpose_document.rb
Overview
A Object to represent the Nexpose xml file in memory
Instance Method Summary collapse
-
#fix_ips ⇒ Object
Fixes the ip field if nil and replaces it with the name if its an ip.
-
#initialize(document) ⇒ NexposeDocument
constructor
Creates a instance of the NexposeDocument class.
-
#parse ⇒ Object
Invokes the SAX parser on the XML document.
-
#valid? ⇒ Boolean
Checks the validness of a Nexpose.
Constructor Details
#initialize(document) ⇒ NexposeDocument
Creates a instance of the NexposeDocument class
31 32 33 |
# File 'lib/risu/parsers/nexpose/nexpose_document.rb', line 31 def initialize document @document = document end |
Instance Method Details
#fix_ips ⇒ Object
Fixes the ip field if nil and replaces it with the name if its an ip
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/risu/parsers/nexpose/nexpose_document.rb', line 65 def fix_ips @hosts = Host.all @hosts.each do |host| if host.ip == nil begin ip = IPAddr.new host.name host.ip = ip.to_string host.save rescue ArgumentError next end end end end |
#parse ⇒ Object
Invokes the SAX parser on the XML document
58 59 60 61 62 |
# File 'lib/risu/parsers/nexpose/nexpose_document.rb', line 58 def parse @parser = LibXML::XML::SaxParser.file @document @parser.callbacks = SimpleNexpose.new @parser.parse end |
#valid? ⇒ Boolean
Checks the validness of a Nexpose
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/risu/parsers/nexpose/nexpose_document.rb', line 38 def valid? if File.exist?(@document) @parser = LibXML::XML::Parser.file @document doc = @parser.parse if doc.root.name == nil return false end if doc.root.name == "NeXposeSimpleXML" return true else return false end else return false end end |