Class: PatchworkInternal::Link

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_a, node_b, directed, cost) ⇒ Link

Returns a new instance of Link.



8
9
10
11
12
13
14
# File 'lib/patchwork/link.rb', line 8

def initialize(node_a, node_b, directed, cost)
  @node_start = node_a
  @node_end = node_b
  @directed = directed
  @cost = cost
  @id = SecureRandom.uuid
end

Instance Attribute Details

#costObject

Returns the value of attribute cost.



6
7
8
# File 'lib/patchwork/link.rb', line 6

def cost
  @cost
end

#directedObject

Returns the value of attribute directed.



6
7
8
# File 'lib/patchwork/link.rb', line 6

def directed
  @directed
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/patchwork/link.rb', line 5

def id
  @id
end

#node_endObject (readonly)

Returns the value of attribute node_end.



5
6
7
# File 'lib/patchwork/link.rb', line 5

def node_end
  @node_end
end

#node_startObject (readonly)

Returns the value of attribute node_start.



5
6
7
# File 'lib/patchwork/link.rb', line 5

def node_start
  @node_start
end

Instance Method Details



16
17
18
19
20
21
22
# File 'lib/patchwork/link.rb', line 16

def links_to(node)
  if @directed == true
    node == @node_end
  else
    node == @node_start || node == @node_end
  end
end