Class: Vizier::SubGraph
Direct Known Subclasses
Graph
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
Returns a new instance of SubGraph.
173
174
175
176
177
178
179
180
181
|
# File 'lib/support/vizier.rb', line 173
def initialize( name, attrs={} )
self.attributes = attrs
@node = {}
@edge = {}
@name = name
@nodes = []
@links = []
end
|
Instance Attribute Details
Returns the value of attribute links.
170
171
172
|
# File 'lib/support/vizier.rb', line 170
def links
@links
end
|
Returns the value of attribute name.
171
172
173
|
# File 'lib/support/vizier.rb', line 171
def name
@name
end
|
Instance Method Details
#add_link(from, to, a = {}) ⇒ Object
Also known as:
connect, add_edge
201
202
203
204
205
|
# File 'lib/support/vizier.rb', line 201
def add_link(from, to, a={})
returning Link.new( from, to, a) do |l|
@links << l
end
end
|
#add_node(n, a = {}) ⇒ Object
195
196
197
198
199
|
# File 'lib/support/vizier.rb', line 195
def add_node( n, a={} )
returning Node.new(n,a) do |n|
@nodes << n
end
end
|
#build(lines = [], indent = 0) ⇒ Object
209
210
211
212
213
214
215
216
217
|
# File 'lib/support/vizier.rb', line 209
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
|
225
226
227
|
# File 'lib/support/vizier.rb', line 225
def (str)
(str, 2)
end
|
#edge(attrs = {}) ⇒ Object
191
192
193
|
# File 'lib/support/vizier.rb', line 191
def edge(attrs={})
(@edge ||= {}).merge!(attrs).extend(Attributes)
end
|
#graph(attrs = {}) ⇒ Object
187
188
189
|
# File 'lib/support/vizier.rb', line 187
def graph(attrs={})
self.attributes.merge!(attrs).extend(Attributes)
end
|
#node(attrs = {}) ⇒ Object
183
184
185
|
# File 'lib/support/vizier.rb', line 183
def node(attrs={})
(@node ||= {}).merge!(attrs).extend(Attributes)
end
|
#to_str ⇒ Object
Also known as:
generate!
229
230
231
232
233
234
235
236
237
238
239
240
241
|
# File 'lib/support/vizier.rb', line 229
def to_str
build( ["subgraph #{quote name} {",
[ ["graph #{attributes};",
"node #{node};",
"edge #{edge};"
],
nodes.map(&:to_str),
links.map(&:to_str),
"}"
],
])
end
|
219
220
221
222
223
|
# File 'lib/support/vizier.rb', line 219
def ( 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
|