Class: Vizier::SubGraph

Inherits:
Base show all
Includes:
Support
Defined in:
lib/support/vizier.rb

Direct Known Subclasses

Graph

Constant Summary

Constant Summary

Constants included from Support

Vizier::Support::LEGAL_CHARS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support

#attributes, #attributes=, included, #legal?, #quote, #sanitize

Methods inherited from Base

#[], #[]=

Constructor Details

#initialize(name, attrs = {}) ⇒ SubGraph



174
175
176
177
178
179
180
181
182
# File 'lib/support/vizier.rb', line 174

def initialize( name, attrs={} )
  self.attributes = attrs
  @node = {}
  @edge = {}

  @name = name
  @nodes = []
  @links = []
end

Instance Attribute Details

Returns the value of attribute links



171
172
173
# File 'lib/support/vizier.rb', line 171

def links
  @links
end

#nameObject

Returns the value of attribute name



172
173
174
# File 'lib/support/vizier.rb', line 172

def name
  @name
end

Instance Method Details



202
203
204
205
206
# File 'lib/support/vizier.rb', line 202

def add_link(from, to, a={})
  returning Link.new( from, to, a) do |l|
    @links << l
  end
end

#add_node(n, a = {}) ⇒ Object



196
197
198
199
200
# File 'lib/support/vizier.rb', line 196

def add_node( n, a={} )
  returning Node.new(n,a) do |n|
    @nodes << n
  end
end

#build(lines = [], indent = 0) ⇒ Object



210
211
212
213
214
215
216
217
218
# File 'lib/support/vizier.rb', line 210

def build(lines = [], indent = 0)
  lines.map do |line|
    if line.is_a?( Array )
      build( line, indent + 1)
    else
      (" " * (indent * 4) ) + line.to_s
    end
  end.join("\n")
end

#comment(str) ⇒ Object



226
227
228
# File 'lib/support/vizier.rb', line 226

def comment(str)
  write_comment(str, 2)
end

#edge(attrs = {}) ⇒ Object



192
193
194
# File 'lib/support/vizier.rb', line 192

def edge(attrs={})
  (@edge ||= {}).merge!(attrs).extend(Attributes)
end

#graph(attrs = {}) ⇒ Object



188
189
190
# File 'lib/support/vizier.rb', line 188

def graph(attrs={})
  self.attributes.merge!(attrs).extend(Attributes)
end

#node(attrs = {}) ⇒ Object



184
185
186
# File 'lib/support/vizier.rb', line 184

def node(attrs={})
  (@node ||= {}).merge!(attrs).extend(Attributes)
end

#to_strObject Also known as: generate!



230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/support/vizier.rb', line 230

def to_str
  build( ["subgraph #{quote name} {",
          [ # attributes.map {|k,v| "#{quote k} = #{quote v};" },
           ["graph #{attributes};",
             "node #{node};",
             "edge #{edge};"
            ],
            nodes.map(&:to_str),
            links.map(&:to_str),
            "}"
           ],
        ])
end

#write_comment(str, j = 0) ⇒ Object



220
221
222
223
224
# File 'lib/support/vizier.rb', line 220

def write_comment( str, j = 0 )
  l = 40 - (j * 4)
  i = ' ' * (j * 4)
  "\n#{i}/*#{'*'*(l-2)}\n#{i}** #{ str.ljust((l - (6) - (j*4)),' ') }#{i} **\n#{i}#{'*'*(l-1)}/"
end