Class: Inspec::Resources::XmlConfig
- Inherits:
-
JsonConfig
- Object
- JsonConfig
- Inspec::Resources::XmlConfig
- Defined in:
- lib/inspec/resources/xml.rb
Instance Attribute Summary
Attributes inherited from JsonConfig
Instance Method Summary collapse
Methods inherited from JsonConfig
#initialize, #method_missing, #to_s
Methods included from FileReader
Methods included from ObjectTraverser
Constructor Details
This class inherits a constructor from Inspec::Resources::JsonConfig
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Inspec::Resources::JsonConfig
Instance Method Details
#parse(content) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/inspec/resources/xml.rb', line 16 def parse(content) require "rexml/document" REXML::Document.new(content) rescue => e raise Inspec::Exceptions::ResourceFailed, "Unable to parse XML: #{e.}" end |
#value(key) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/inspec/resources/xml.rb', line 23 def value(key) output = [] REXML::XPath.each(@params, key.first.to_s) do |element| if element.is_a?(REXML::Attribute) output.push(element.to_s) elsif element.is_a?(REXML::Element) output.push(element.text) elsif element.is_a?(Integer) || element.is_a?(TrueClass) || element.is_a?(FalseClass) || element.is_a?(String) output.push(element) else raise Inspec::Exceptions::ResourceFailed, "Unknown XML object received (#{element.class}): #{element}" end end output end |