Module: Rex::Parser::GraphML
- Defined in:
- lib/rex/parser/graphml.rb
Overview
A partial implementation of the GraphML specification for loading structured data from an XML file. Notable missing components include GraphML parse meta-data (XML attributes with the “parse” prefix), hyperedges and ports. See: graphml.graphdrawing.org/
Defined Under Namespace
Modules: Element, Error Classes: AttributeContainer, Document, MetaAttribute
Class Method Summary collapse
-
.convert_attribute(attr_type, value) ⇒ Object
Convert a GraphML value string into a Ruby value depending on the specified type.
-
.from_file(file_path) ⇒ Rex::Parser::GraphML::Element::GraphML
Load the contents of a GraphML file by parsing it with Nokogiri and returning the top level GraphML structure.
Class Method Details
.convert_attribute(attr_type, value) ⇒ Object
Convert a GraphML value string into a Ruby value depending on the specified type. Values of int and long will be converted to Ruby integer, while float and double values will be converted to floats. For booleans, values that are either blank or “false” (case-insensitive) will evaluate to Ruby’s false, while everything else will be true.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rex/parser/graphml.rb', line 30 def self.convert_attribute(attr_type, value) case attr_type when :boolean value.strip! if value.blank? value = false else value = value.downcase != 'false' end when :int, :long value = Integer(value) when :float, :double value = Float(value) when :string # rubocop:disable Lint/EmptyWhen else raise ArgumentError, 'Unsupported attribute type: ' + attr_type.to_s end value end |
.from_file(file_path) ⇒ Rex::Parser::GraphML::Element::GraphML
Load the contents of a GraphML file by parsing it with Nokogiri and returning the top level GraphML structure.
17 18 19 20 21 |
# File 'lib/rex/parser/graphml.rb', line 17 def self.from_file(file_path) parser = Nokogiri::XML::SAX::Parser.new(Document.new) parser.parse(File.read(file_path, mode: 'rb')) parser.document.graphml end |