class RGL::DOT::Node
A node representation. Edges are drawn between nodes. The rendering of a node depends upon the options set for it.
Attributes
Public Class Methods
Source
# File lib/rgl/rdot.rb 300 def initialize(params = {}, option_list = NODE_OPTS+NODE_OPTS_LGCY) 301 super(params, option_list) 302 @ports = params['ports'] ? params['ports'] : [] 303 end
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.
Calls superclass method
RGL::DOT::Element::new
Public Instance Methods
Source
# File lib/rgl/rdot.rb 310 def to_s(leader = '', indent = ' ') 311 label_option = nil 312 313 if @options['shape'] =~ /^M?record$/ && !@ports.empty? 314 # Ignore the given label option in this case since the ports should each 315 # provide their own name/label. 316 label_option = leader + indent + "#{quote_ID('label')} = #{quote_ID(@ports.collect { |port| port.to_s }.join(" | "))}" 317 elsif @options['label'] 318 # Otherwise, use the label when given one. 319 label_option = leader + indent + "#{quote_ID('label')} = #{quote_label(@options['label'])}" 320 end 321 322 # Convert all the options except `label' and options with nil values 323 # straight into name = value pairs. Then toss out any resulting nil 324 # entries in the final array. 325 stringified_options = @options.collect do |name, val| 326 unless name == 'label' || val.nil? 327 leader + indent + "#{quote_ID(name)} = #{quote_ID(val)}" 328 end 329 end.compact 330 331 # Append the specially computed label option. 332 stringified_options.push(label_option) unless label_option.nil? 333 334 # Join them all together. 335 stringified_options = stringified_options.join(",\n") 336 337 # Put it all together into a single string with indentation and return the 338 # result. 339 if stringified_options.empty? 340 leader + quote_ID(@name) unless @name.nil? 341 else 342 leader + (@name.nil? ? '' : quote_ID(@name) + " ") + "[\n" + 343 stringified_options + "\n" + 344 leader + "]" 345 end 346 end
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.