Module: Connected::Edge

Includes:
Comparable
Included in:
GenericConnection
Defined in:
lib/connected/edge.rb

Overview

Used to mixin a direct connection between two Vertices (an Edge) on a graph

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/connected/edge.rb', line 41

def <=>(other)
  if (open? && other.open?) || (closed? && other.closed?)
    metric <=> other.metric
  elsif open?
    -1
  elsif other.open?
    1
  end
end

#closed?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/connected/edge.rb', line 23

def closed?
  unless respond_to?(:state)
    # Expect classes to describe how to determine if they're closed
    raise "#state() or #closed? MUST be implemented on #{self.class.name}"
  end

  state.to_s == :closed.to_s
end

#fromObject



8
9
10
11
# File 'lib/connected/edge.rb', line 8

def from
  # Expect classes to describe the "from" Vertex
  raise "#from() MUST be implemented on #{self.class.name}"
end

#metricObject

This should almost certainly be overridden



19
20
21
# File 'lib/connected/edge.rb', line 19

def metric
  1
end

#open?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
# File 'lib/connected/edge.rb', line 32

def open?
  unless respond_to?(:state)
    # Expect classes to describe how to determine if they're open
    raise "#state() or #open? MUST be implemented on #{self.class.name}"
  end

  state.to_s == :open.to_s
end

#toObject



13
14
15
16
# File 'lib/connected/edge.rb', line 13

def to
  # Expect classes to describe the "to" Vertex
  raise "#to() MUST be implemented on #{self.class.name}"
end