Class: Rex::Parser::GraphML::Element::Edge

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

Overview

An edge element defines a connection between two nodes. Connections are optionally directional. See: graphml.graphdrawing.org/specification/xsd.html#element-edge

Constant Summary collapse

ELEMENT_NAME =
'edge'.freeze

Instance Attribute Summary collapse

Attributes inherited from AttributeContainer

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, target, directed, id: nil) ⇒ Edge

Returns a new instance of Edge.

Parameters:

  • source (String)

    The id of the node that this edge originated from.

  • target (String)

    The id of the node that this edge is destined for.

  • directed (Boolean)

    Whether or not this edge only connects in one direction.

  • id (String) (defaults to: nil)

    The optional, unique identifier of this edge.



185
186
187
188
189
190
191
# File 'lib/rex/parser/graphml.rb', line 185

def initialize(source, target, directed, id: nil)
  @source = source
  @target = target
  @directed = directed
  @id = id
  super()
end

Instance Attribute Details

#directedObject (readonly)

!@attribute directed

@return [Boolean] Whether or not this edge only connects in one direction.


220
221
222
# File 'lib/rex/parser/graphml.rb', line 220

def directed
  @directed
end

#idObject (readonly)

!@attribute id

@return [String] The optional, unique identifier of this edge.


223
224
225
# File 'lib/rex/parser/graphml.rb', line 223

def id
  @id
end

#sourceObject (readonly)

!@attribute source

@return [String] The id of the node that this edge originated from.


214
215
216
# File 'lib/rex/parser/graphml.rb', line 214

def source
  @source
end

#targetObject (readonly)

!@attribute target

@return [String] The id of the node that this edge is destined for.


217
218
219
# File 'lib/rex/parser/graphml.rb', line 217

def target
  @target
end

Class Method Details

.from_xml_attributes(xml_attrs, edgedefault) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/rex/parser/graphml.rb', line 193

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

  target = xml_attrs['target']
  raise Error::InvalidAttributeError.new('edge', 'target') if target.nil?

  directed = xml_attrs['directed']
  if directed.nil?
    directed = edgedefault == :directed
  elsif %w[true false].include? directed
    directed = directed == 'true'
  else
    raise Error::InvalidAttributeError.new('edge', 'directed', details: 'must be either true or false when specified', missing: false)
  end

  new(source, target, directed, id: xml_attrs['id'])
end