Class: DOT::DOTSubgraph

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

Overview

A 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.



234
235
236
237
238
# File 'lib/puppet/external/dot.rb', line 234

def initialize(params = {}, option_list = GRAPH_OPTS)
  super(params, option_list)
  @nodes      = params['nodes'] || []
  @dot_string = 'graph'
end

Instance Method Details

#<<(thing) ⇒ Object



244
245
246
# File 'lib/puppet/external/dot.rb', line 244

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

#each_nodeObject



240
241
242
# File 'lib/puppet/external/dot.rb', line 240

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

#popObject



252
253
254
# File 'lib/puppet/external/dot.rb', line 252

def pop
  @nodes.pop
end

#push(thing) ⇒ Object



248
249
250
# File 'lib/puppet/external/dot.rb', line 248

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

#to_s(t = '') ⇒ Object



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/puppet/external/dot.rb', line 256

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

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

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