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
ports[RW]
Public Class Methods
new(params = {}, option_list = NODE_OPTS)
click to toggle source
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
# File lib/rgl/rdot.rb 247 def initialize(params = {}, option_list = NODE_OPTS) 248 super(params, option_list) 249 @ports = params['ports'] ? params['ports'] : [] 250 end
Public Instance Methods
to_s(leader = '', indent = ' ')
click to toggle source
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.
# File lib/rgl/rdot.rb 257 def to_s(leader = '', indent = ' ') 258 label_option = nil 259 260 if @options['shape'] =~ /^M?record$/ && !@ports.empty? 261 # Ignore the given label option in this case since the ports should each 262 # provide their own name/label. 263 label_option = leader + indent + "#{quote_ID('label')} = #{quote_ID(@ports.collect { |port| port.to_s }.join(" | "))}" 264 elsif @options['label'] 265 # Otherwise, use the label when given one. 266 label_option = leader + indent + "#{quote_ID('label')} = #{quote_label(@options['label'])}" 267 end 268 269 # Convert all the options except `label' and options with nil values 270 # straight into name = value pairs. Then toss out any resulting nil 271 # entries in the final array. 272 stringified_options = @options.collect do |name, val| 273 unless name == 'label' || val.nil? 274 leader + indent + "#{quote_ID(name)} = #{quote_ID(val)}" 275 end 276 end.compact 277 278 # Append the specially computed label option. 279 stringified_options.push(label_option) unless label_option.nil? 280 281 # Join them all together. 282 stringified_options = stringified_options.join(",\n") 283 284 # Put it all together into a single string with indentation and return the 285 # result. 286 if stringified_options.empty? 287 leader + quote_ID(@name) unless @name.nil? 288 else 289 leader + (@name.nil? ? '' : quote_ID(@name) + " ") + "[\n" + 290 stringified_options + "\n" + 291 leader + "]" 292 end 293 end