Class: RGL::DOT::Node
Overview
A node representation. Edges are drawn between nodes. The rendering of a node depends upon the options set for it.
Instance Attribute Summary collapse
-
#ports ⇒ Object
Returns the value of attribute ports.
Instance Method Summary collapse
-
#initialize(params = {}, option_list = NODE_OPTS+NODE_OPTS_LGCY) ⇒ Node
constructor
Creates a new Node with the params Hash providing settings for all node options.
-
#to_s(leader = '', indent = ' ') ⇒ Object
Returns a string representation of this node which is consumable by the graphviz tools
dot
andneato
.
Constructor Details
#initialize(params = {}, option_list = NODE_OPTS+NODE_OPTS_LGCY) ⇒ Node
Creates a new Node with the params Hash providing settings for all node options. The option_list parameter restricts those options to the list of valid names it contains. The exception to this is the ports option which, if specified, must be an Enumerable containing a list of ports.
300 301 302 303 |
# File 'lib/rgl/rdot.rb', line 300 def initialize(params = {}, option_list = NODE_OPTS+NODE_OPTS_LGCY) super(params, option_list) @ports = params['ports'] ? params['ports'] : [] end |
Instance Attribute Details
#ports ⇒ Object
Returns the value of attribute ports.
292 293 294 |
# File 'lib/rgl/rdot.rb', line 292 def ports @ports end |
Instance Method Details
#to_s(leader = '', indent = ' ') ⇒ Object
Returns a string representation of this node which is consumable by the graphviz tools dot
and neato
. The leader parameter is used to indent every line of the returned string, and the indent parameter is used to additionally indent nested items.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/rgl/rdot.rb', line 310 def to_s(leader = '', indent = ' ') label_option = nil if @options['shape'] =~ /^M?record$/ && !@ports.empty? # Ignore the given label option in this case since the ports should each # provide their own name/label. label_option = leader + indent + "#{quote_ID('label')} = #{quote_ID(@ports.collect { |port| port.to_s }.join(" | "))}" elsif @options['label'] # Otherwise, use the label when given one. label_option = leader + indent + "#{quote_ID('label')} = #{quote_label(@options['label'])}" end # Convert all the options except `label' and options with nil values # straight into name = value pairs. Then toss out any resulting nil # entries in the final array. = @options.collect do |name, val| unless name == 'label' || val.nil? leader + indent + "#{quote_ID(name)} = #{quote_ID(val)}" end end.compact # Append the specially computed label option. .push(label_option) unless label_option.nil? # Join them all together. = .join(",\n") # Put it all together into a single string with indentation and return the # result. if .empty? leader + quote_ID(@name) unless @name.nil? else leader + (@name.nil? ? '' : quote_ID(@name) + " ") + "[\n" + + "\n" + leader + "]" end end |