Class: Tinydot::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/tinydot/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attrs) ⇒ Node

Returns a new instance of Node.



5
6
7
8
9
# File 'lib/tinydot/node.rb', line 5

def initialize(name, attrs)
  @name = name
  @edges = []
  @attrs = attrs || {}
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



3
4
5
# File 'lib/tinydot/node.rb', line 3

def attrs
  @attrs
end

#edgesObject (readonly)

Returns the value of attribute edges.



3
4
5
# File 'lib/tinydot/node.rb', line 3

def edges
  @edges
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/tinydot/node.rb', line 3

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object



16
17
18
19
# File 'lib/tinydot/node.rb', line 16

def <=>(other)
  @edges << Edge.new(self, other, dir: "both")
  other
end

#>>(other) ⇒ Object



11
12
13
14
# File 'lib/tinydot/node.rb', line 11

def >>(other)
  @edges << Edge.new(self, other)
  other
end

#to_dotObject



21
22
23
24
25
26
# File 'lib/tinydot/node.rb', line 21

def to_dot
  quoted_attrs = %i(label color fillcolor fontname)
  @attrs.map do |k, v|
    quoted_attrs.include?(k) ? %(#{k} = "#{v}") : %(#{k} = #{v})
  end.join(", ")
end