class ALD::Definition
Access information in ALD package definition files.
Public
↑ topPublic Class Methods
Open a new definition file for analysis.
- source
-
the source to read the definition from. This can be a Nokogiri::XML::Document, a String or any object that responds to #read and #close.
Examples¶ ↑
definition = ALD::Definition.new('/path/to/def.xml')
Raises ALD::InvalidDefinitionError if the supplied source is not a valid ALD package definition.
# File lib/ALD/definition.rb, line 99 def initialize(source) if source.is_a? Nokogiri::XML::Document @document = source else @document = Nokogiri::XML(source) { |config| config.nonet } end raise InvalidDefinitionError unless valid? end
Public Instance Methods
Get the XML string representing the definition
# File lib/ALD/definition.rb, line 162 def to_s @document.to_s end
Internal
↑ topConstants
- SCHEMA_FILE
Path to the file containing the XML Schema Definition used for definition validation.
- TOPLEVEL_ATTRIBUTES
The array of attributes which are defined in the root element of a definition. Each of these gets a dynamically defined method.
- XML_NAMESPACE
The XML namespace used by the definitions.
Public Class Methods
Public Instance Methods
Private Instance Methods
Get an Array of attribute Hashes from a list of elements in the definition.
- xpath
-
the XPath String pointing to the XML elements in the definition
- keys
-
the Array of keys to retrieve from the elements
Returns¶ ↑
Returns an Array of Hashes, where each Hash has all those of the given keys that were actual attributes on the relevant element.
# File lib/ALD/definition.rb, line 176 def attribute_hash(xpath, keys) @document.xpath(xpath, 'ald' => XML_NAMESPACE).map do |e| Hash[keys.map { |k| e.attribute_with_ns(k, XML_NAMESPACE) }.compact.map { |a| [a.node_name, a.value] }] end end