Class: Rex::Parser::GraphML::Element::Node

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

Overview

A node element defines an object within the graph that can have zero or more edges connecting it to other nodes. A node element may contain a graph element.

Constant Summary collapse

ELEMENT_NAME =
'node'.freeze

Instance Attribute Summary collapse

Attributes inherited from AttributeContainer

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Node

Returns a new instance of Node.

Parameters:

  • id (String)

    The unique identifier for this node element.



362
363
364
365
366
367
# File 'lib/rex/parser/graphml.rb', line 362

def initialize(id)
  @id = id
  @edges = []
  @subgraph = nil
  super()
end

Instance Attribute Details

#edgesObject

Returns the value of attribute edges.



393
394
395
# File 'lib/rex/parser/graphml.rb', line 393

def edges
  @edges
end

#idObject

Returns the value of attribute id.



390
391
392
# File 'lib/rex/parser/graphml.rb', line 390

def id
  @id
end

#subgraphGraph?

Returns A subgraph contained within this node.

Returns:

  • (Graph, nil)

    A subgraph contained within this node.



396
397
398
# File 'lib/rex/parser/graphml.rb', line 396

def subgraph
  @subgraph
end

Class Method Details

.from_xml_attributes(xml_attrs) ⇒ Object



369
370
371
372
373
374
# File 'lib/rex/parser/graphml.rb', line 369

def self.from_xml_attributes(xml_attrs)
  id = xml_attrs['id']
  raise Error::InvalidAttributeError.new('node', 'id') if id.nil?

  new(id)
end

Instance Method Details

#source_edgesArray

Returns An array of all edges for which this node is the target.

Returns:

  • (Array)

    An array of all edges for which this node is the target.



377
378
379
380
# File 'lib/rex/parser/graphml.rb', line 377

def source_edges
  # edges connected to this node
  @edges.select { |edge| edge.target == @id || !edge.directed }
end

#target_edgesArray

Returns An array of all edges for which this node is the source.

Returns:

  • (Array)

    An array of all edges for which this node is the source.



383
384
385
386
# File 'lib/rex/parser/graphml.rb', line 383

def target_edges
  # edges connecting this to other nodes
  @edges.select { |edge| edge.source == @id || !edge.directed }
end