Class: PatchworkInternal::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/patchwork/node.rb', line 8

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/patchwork/node.rb', line 7

def id
  @id
end

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


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_nodesObject



24
25
26
# File 'lib/patchwork/node.rb', line 24

def linked_nodes
  @links.map(&:node_end)
end

#neighbor?(node) ⇒ Boolean

Returns:

  • (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

Yields:

  • (_self)

Yield Parameters:



32
33
34
# File 'lib/patchwork/node.rb', line 32

def visit
  yield self
end