Module: OpenvasCli::XmlAddin::ClassMethods

Defined in:
lib/openvas-cli/xml_addin.rb

Instance Method Summary collapse

Instance Method Details

#extract_value_from(x_str, n) ⇒ Object

Helper method to extract a value from a Nokogiri::XML::Node object. If the xpath provided contains an @, then the method assumes that the value resides in an attribute, otherwise it pulls the text of the last text node.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/openvas-cli/xml_addin.rb', line 11

def extract_value_from(x_str, n)
  ret = ""
  if x_str =~ /@/
    ret = n.at_xpath(x_str).value  if n.at_xpath(x_str)
  else
    tn =  n.at_xpath(x_str)
    if tn
      if tn.children.count > 0
        tn.children.each { |tnc|
          if tnc.text?
            ret = tnc.text
          end
        }
      else
        ret = tn.text
      end
    end
  end
  
  ret
end