Class: DOT::DOTSubgraph

Inherits:
DOTElement show all
Defined in:
lib/rdoc/dot/dot.rb

Overview

subgraph element is the same to graph, but has another header in dot notation

Direct Known Subclasses

DOTDigraph

Instance Attribute Summary

Attributes inherited from DOTElement

#name, #options

Attributes inherited from DOTSimpleElement

#name

Instance Method Summary collapse

Methods inherited from DOTElement

#each_option, #each_option_pair

Constructor Details

#initialize(params = {}, option_list = GRAPH_OPTS) ⇒ DOTSubgraph

Returns a new instance of DOTSubgraph.



188
189
190
191
192
# File 'lib/rdoc/dot/dot.rb', line 188

def initialize( params = {}, option_list = GRAPH_OPTS )
    super( params, option_list )
    @nodes = params['nodes'] ? params['nodes'] : []
    @dot_string = 'subgraph'
end

Instance Method Details

#<<(thing) ⇒ Object



198
199
200
# File 'lib/rdoc/dot/dot.rb', line 198

def << ( thing )
    @nodes << thing
end

#each_nodeObject



194
195
196
# File 'lib/rdoc/dot/dot.rb', line 194

def each_node
    @nodes.each{ |i| yield i }
end

#popObject



206
207
208
# File 'lib/rdoc/dot/dot.rb', line 206

def pop
    @nodes.pop
end

#push(thing) ⇒ Object



202
203
204
# File 'lib/rdoc/dot/dot.rb', line 202

def push( thing )
    @nodes.push( thing )
end

#to_s(t = '') ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/rdoc/dot/dot.rb', line 210

def to_s( t = '' )
  hdr = t + "#{@dot_string} #{@name} {\n"

  options = @options.to_a.collect{ |name, val|
    val && name != 'label' ?
    t + $tab + "#{name} = #{val}" :
      name ? t + $tab + "#{name} = \"#{val}\"" : nil
  }.compact.join( "\n" ) + "\n"

  nodes = @nodes.collect{ |i|
    i.to_s( t + $tab )
  }.join( "\n" ) + "\n"
  hdr + options + nodes + t + "}\n"
end