class RGL::DOT::Graph

A graph representation. Whether or not it is rendered as directed or undirected depends on which of the programs dot or neato is used to process and render the graph.

Public Class Methods

new(params = {}, option_list = GRAPH_OPTS+GRAPH_OPTS_LGCY) click to toggle source

Creates a new Graph with the params Hash providing settings for all graph options. The option_list parameter restricts those options to the list of valid names it contains. The exception to this is the elements option which, if specified, must be an Enumerable containing a list of nodes, edges, and/or subgraphs.

Calls superclass method RGL::DOT::Element::new
    # File lib/rgl/rdot.rb
361 def initialize(params = {}, option_list = GRAPH_OPTS+GRAPH_OPTS_LGCY)
362   super(params, option_list)
363   @elements   = params['elements'] ? params['elements'] : []
364   @dot_string = 'graph'
365 end

Public Instance Methods

graph << element → graph click to toggle source

Adds a new node, edge, or subgraph to this graph.

    # File lib/rgl/rdot.rb
383 def <<(element)
384   @elements << element
385   self
386 end
Also aliased as: push
each_element {|element| block} → graph click to toggle source

Calls block once for each node, edge, or subgraph contained by this graph, passing the node, edge, or subgraph to the block.

    # File lib/rgl/rdot.rb
373 def each_element(&block)
374   @elements.each(&block)
375   self
376 end
pop → element click to toggle source

Removes the most recently added node, edge, or subgraph from this graph and returns it.

    # File lib/rgl/rdot.rb
396 def pop
397   @elements.pop
398 end
push(element)
Alias for: <<
to_s(leader = '', indent = ' ') click to toggle source

Returns a string representation of this graph 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
405 def to_s(leader = '', indent = '    ')
406   hdr = leader + @dot_string + (@name.nil? ? '' : ' ' + quote_ID(@name)) + " {\n"
407 
408   options = @options.to_a.collect do |name, val|
409     unless val.nil?
410       if name == 'label'
411         leader + indent + "#{quote_ID(name)} = #{quote_label(val)}"
412       else
413         leader + indent + "#{quote_ID(name)} = #{quote_ID(val)}"
414       end
415     end
416   end.compact.join("\n")
417 
418   elements = @elements.collect do |element|
419     element.to_s(leader + indent, indent)
420   end.join("\n\n")
421 
422   hdr + (options.empty? ? '' : options + "\n\n") +
423   (elements.empty? ? '' : elements + "\n") + leader + "}"
424 end