Class: PatchworkInternal::Node
- Inherits:
-
Object
- Object
- PatchworkInternal::Node
- Defined in:
- lib/patchwork/node.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
Instance Method Summary collapse
- #depth_first(&block) ⇒ Object
-
#initialize(data) ⇒ Node
constructor
A new instance of Node.
- #link_to(node, directed = false, cost = nil) ⇒ Object
- #linked_nodes ⇒ Object
- #neighbor?(node) ⇒ Boolean
- #visit {|_self| ... } ⇒ Object
Constructor Details
#initialize(data) ⇒ Node
Returns a new instance of Node.
11 12 13 14 15 |
# File 'lib/patchwork/node.rb', line 11 def initialize(data) @data = data @links = [] @id = SecureRandom.uuid end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/patchwork/node.rb', line 8 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/patchwork/node.rb', line 7 def id @id end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
9 10 11 |
# File 'lib/patchwork/node.rb', line 9 def links @links end |
Instance Method Details
#depth_first(&block) ⇒ Object
36 37 38 |
# File 'lib/patchwork/node.rb', line 36 def depth_first(&block) Traversals.depth_first(self, &block) end |
#link_to(node, directed = false, cost = nil) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/patchwork/node.rb', line 17 def link_to(node, directed = false, cost = nil) return false if neighbor?(node) @links << Link.new(self, node, directed, cost) node.link_to(self) unless directed true end |
#linked_nodes ⇒ Object
24 25 26 |
# File 'lib/patchwork/node.rb', line 24 def linked_nodes @links.map(&:node_end) end |
#neighbor?(node) ⇒ Boolean
28 29 30 |
# File 'lib/patchwork/node.rb', line 28 def neighbor?(node) @links.any? { |link| link.links_to(node) } end |
#visit {|_self| ... } ⇒ Object
32 33 34 |
# File 'lib/patchwork/node.rb', line 32 def visit yield self end |