Module: Connected::Edge
Overview
Used to mixin a direct connection between two Vertices (an Edge) on a graph
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #closed? ⇒ Boolean
- #from ⇒ Object
-
#metric ⇒ Object
This should almost certainly be overridden.
- #open? ⇒ Boolean
- #to ⇒ Object
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
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 |
#from ⇒ Object
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 |
#metric ⇒ Object
This should almost certainly be overridden
19 20 21 |
# File 'lib/connected/edge.rb', line 19 def metric 1 end |
#open? ⇒ 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 |
#to ⇒ Object
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 |