Class: RGL::DOT::Port

Inherits:
Object
  • Object
show all
Defined in:
lib/rgl/rdot.rb

Overview

Ports are used when a Node instance has its ‘shape’ option set to record or Mrecord. Ports can be nested.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name_or_ports = nil, label = nil) ⇒ Port

Create a new port with either an optional name and label or a set of nested ports.

:call-seq:

new(name = nil, label = nil)
new(ports)

A nil value for name is valid; otherwise, it must be a String or it will be interpreted as ports.



261
262
263
264
265
266
267
268
269
270
271
# File 'lib/rgl/rdot.rb', line 261

def initialize(name_or_ports = nil, label = nil)
  if name_or_ports.nil? || name_or_ports.kind_of?(String)
    @name  = name_or_ports
    @label = label
    @ports = nil
  else
    @ports = name_or_ports
    @name  = nil
    @label = nil
  end
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



249
250
251
# File 'lib/rgl/rdot.rb', line 249

def label
  @label
end

#nameObject

Returns the value of attribute name.



249
250
251
# File 'lib/rgl/rdot.rb', line 249

def name
  @name
end

#portsObject

Returns the value of attribute ports.



249
250
251
# File 'lib/rgl/rdot.rb', line 249

def ports
  @ports
end

Instance Method Details

#to_sObject

Returns a string representation of this port. If ports is a non-empty Enumerable, a nested ports representation is returned; otherwise, a name-label representation is returned.



277
278
279
280
281
282
283
284
# File 'lib/rgl/rdot.rb', line 277

def to_s
  if @ports.nil? || @ports.empty?
    n = (name.nil? || name.empty?) ? '' : "<#{name}>"
    n + ((n.empty? || label.nil? || label.empty?) ? '' : ' ') + label.to_s
  else
    '{' + @ports.collect { |p| p.to_s }.join(' | ') + '}'
  end
end