class Nikto::Item
This class represents each of the <item> elements in the Nikto
XML document.
It provides a convenient way to access the information scattered all over the XML in attributes and nested tags.
Instead of providing separate methods for each supported property we rely on Ruby's method_missing
to do most of the work.
Public Class Methods
new(xml_node)
click to toggle source
Accepts an XML node from Nokogiri::XML.
# File lib/nikto/item.rb, line 12 def initialize(xml_node) @xml = xml_node end
Public Instance Methods
method_missing(method, *args)
click to toggle source
This method is invoked by Ruby when a method that is not defined in this instance is called.
In our case we inspect the @method@ parameter and try to find the attribute, simple descendent or collection that it maps to in the XML tree.
Calls superclass method
# File lib/nikto/item.rb, line 41 def method_missing(method, *args) # We could remove this check and return nil for any non-recognized tag. # The problem would be that it would make tricky to debug problems with # typos. For instance: <>.potr would return nil instead of raising an # exception unless supported_tags.include?(method) super return end # We need the translations_table because 'method' is a reserved word translations_table = { request_method: 'method' } method_name = translations_table.fetch(method, method.to_s) # First we try the attributes return @xml.attributes[method_name].value if @xml.attributes.key?(method_name) # Then we try simple children tags tag = @xml.xpath("./#{ method_name }").first if tag return tag.text end end
respond_to?(method, include_private=false)
click to toggle source
This allows external callers (and specs) to check for implemented properties
Calls superclass method
# File lib/nikto/item.rb, line 30 def respond_to?(method, include_private=false) return true if supported_tags.include?(method.to_sym) super end