Class: Graphy::Node
- Inherits:
-
Object
- Object
- Graphy::Node
- Defined in:
- lib/graphy/node.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#diagram ⇒ Object
Returns the value of attribute diagram.
-
#name ⇒ Object
Returns the value of attribute name.
-
#shape ⇒ Object
Returns the value of attribute shape.
Class Method Summary collapse
Instance Method Summary collapse
- #add_dependency(dependency, **options) ⇒ Object (also: #uses)
- #build(&block) ⇒ Object
- #gnode ⇒ Object
-
#initialize(**params) ⇒ Node
constructor
A new instance of Node.
- #to_s ⇒ Object
Constructor Details
#initialize(**params) ⇒ Node
Returns a new instance of Node.
16 17 18 19 20 |
# File 'lib/graphy/node.rb', line 16 def initialize(**params) @name = params[:name].to_s @diagram = params[:diagram] @shape = params.fetch(:shape, 'circle') end |
Instance Attribute Details
#diagram ⇒ Object
Returns the value of attribute diagram.
3 4 5 |
# File 'lib/graphy/node.rb', line 3 def diagram @diagram end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/graphy/node.rb', line 3 def name @name end |
#shape ⇒ Object
Returns the value of attribute shape.
3 4 5 |
# File 'lib/graphy/node.rb', line 3 def shape @shape end |
Class Method Details
Instance Method Details
#add_dependency(dependency, **options) ⇒ Object Also known as: uses
22 23 24 25 26 27 28 |
# File 'lib/graphy/node.rb', line 22 def add_dependency(dependency, **) dependency = self.class.for(dependency, diagram: diagram) return if Registry.edge?(self, dependency) Registry.add_edge(self, dependency) draw_edge(dependency, **) end |
#build(&block) ⇒ Object
31 32 33 34 |
# File 'lib/graphy/node.rb', line 31 def build(&block) instance_eval(&block) if block_given? gnode end |
#gnode ⇒ Object
36 37 38 |
# File 'lib/graphy/node.rb', line 36 def gnode @gnode ||= find_or_draw end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/graphy/node.rb', line 40 def to_s "#{self.class}<#{name}>" end |