Class: GraphvizR::Node
- Inherits:
-
Object
- Object
- GraphvizR::Node
- Defined in:
- lib/graphviz_r.rb
Overview
This represents graphviz node.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#-(node) ⇒ Object
generate an edge from self to given node.
-
#>>(node) ⇒ Object
generate an edge from self to given node.
-
#[](attributes) ⇒ Object
if blank between node and attributes does not exist, this method is used.
-
#initialize(name, args, parent) ⇒ Node
constructor
A new instance of Node.
-
#to_dot(indent = 0) ⇒ Object
to dot format.
-
#to_s ⇒ Object
to string.
Constructor Details
#initialize(name, args, parent) ⇒ Node
Returns a new instance of Node.
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/graphviz_r.rb', line 241 def initialize(name, args, parent) @parent = parent @name = name @edge = nil @port = nil @attributes = {} unless args.empty? arg = args[0] if arg.is_a? Symbol @port = arg @attributes = {} elsif arg.is_a? Array @port = nil @attributes = arg[0] end end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
239 240 241 |
# File 'lib/graphviz_r.rb', line 239 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
239 240 241 |
# File 'lib/graphviz_r.rb', line 239 def parent @parent end |
Instance Method Details
#-(node) ⇒ Object
generate an edge from self to given node. this generates a undirected edge.
275 276 277 278 |
# File 'lib/graphviz_r.rb', line 275 def -(node) @parent.to_graph @edge = Edge.new self, node, @parent, '--' end |
#>>(node) ⇒ Object
generate an edge from self to given node. this generates a directed edge.
268 269 270 271 |
# File 'lib/graphviz_r.rb', line 268 def >>(node) @parent.to_digraph @edge = Edge.new self, node, @parent end |
#[](attributes) ⇒ Object
if blank between node and attributes does not exist, this method is used. otherwise GraphvizR#[] is used. ex) gvr.graph[:label => ‘example’, :size => ‘1.5, 2.5’]
262 263 264 |
# File 'lib/graphviz_r.rb', line 262 def [](attributes) @attributes = attributes end |
#to_dot(indent = 0) ⇒ Object
to dot format
290 291 292 293 |
# File 'lib/graphviz_r.rb', line 290 def to_dot(indent=0) attributes = @attributes.empty? ? '' : ' ' + @attributes.to_dot "#{INDENT_UNIT * indent}#{@name}#{attributes};\n" end |
#to_s ⇒ Object
to string
281 282 283 284 285 286 287 |
# File 'lib/graphviz_r.rb', line 281 def to_s if @port "#{@name}:#{@port}" else @name end end |