Class: Rex::Parser::GraphML::Element::Graph

Inherits:
AttributeContainer show all
Defined in:
lib/rex/parser/graphml.rb

Overview

A graph element defines a collection of nodes and edges. See: graphml.graphdrawing.org/specification/xsd.html#element-graph

Constant Summary collapse

ELEMENT_NAME =
'graph'.freeze

Instance Attribute Summary collapse

Attributes inherited from AttributeContainer

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(edgedefault, id: nil) ⇒ Graph

Returns a new instance of Graph.

Parameters:

  • edgedefault (Boolean)

    Whether or not edges within this graph should be directional by default.

  • id (String) (defaults to: nil)

    The optional, unique identifier of this graph.


234
235
236
237
238
239
240
241
# File 'lib/rex/parser/graphml.rb', line 234

def initialize(edgedefault, id: nil)
  @edgedefault = edgedefault
  @id = id

  @nodes = {}
  @edges = []
  super()
end

Instance Attribute Details

#edgedefaultObject

Returns the value of attribute edgedefault


257
258
259
# File 'lib/rex/parser/graphml.rb', line 257

def edgedefault
  @edgedefault
end

#edgesObject

Returns the value of attribute edges


263
264
265
# File 'lib/rex/parser/graphml.rb', line 263

def edges
  @edges
end

#idObject

Returns the value of attribute id


260
261
262
# File 'lib/rex/parser/graphml.rb', line 260

def id
  @id
end

#nodesObject

Returns the value of attribute nodes


266
267
268
# File 'lib/rex/parser/graphml.rb', line 266

def nodes
  @nodes
end

Class Method Details

.from_xml_attributes(xml_attrs) ⇒ Object


243
244
245
246
247
248
249
250
251
252
253
# File 'lib/rex/parser/graphml.rb', line 243

def self.from_xml_attributes(xml_attrs)
  edgedefault = xml_attrs['edgedefault']
  unless %w[directed undirected].include? edgedefault
    # see: http://graphml.graphdrawing.org/primer/graphml-primer.html section 2.3.1
    raise Error::InvalidAttributeError.new('graph', 'edgedefault', missing: edgedefault.nil?)
  end

  edgedefault = edgedefault.to_sym

  new(edgedefault, id: xml_attrs['id'])
end