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
# File 'lib/rex/parser/graphml.rb', line 362

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

Instance Attribute Details

#edgesObject

Returns the value of attribute edges


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

def edges
  @edges
end

#idObject

Returns the value of attribute id


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

def id
  @id
end

Class Method Details

.from_xml_attributes(xml_attrs) ⇒ Object


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

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.


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

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.


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

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