Class: EnumMachineContrib::Edge
- Inherits:
-
Struct
- Object
- Struct
- EnumMachineContrib::Edge
- Defined in:
- lib/enum_machine_contrib/edge.rb
Constant Summary collapse
- EDGE_MODES =
rubocop:disable Lint/ConstantDefinitionInBlock
%i[pending dropped].freeze
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #dropped! ⇒ Object
-
#initialize(from, to) ⇒ Edge
constructor
A new instance of Edge.
- #inspect ⇒ Object
- #resolved! ⇒ Object
- #resolved? ⇒ Boolean
Constructor Details
#initialize(from, to) ⇒ Edge
Returns a new instance of Edge.
11 12 13 14 15 16 17 |
# File 'lib/enum_machine_contrib/edge.rb', line 11 def initialize(from, to) self.from = from self.to = to @resolved = false pending! end |
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from
5 6 7 |
# File 'lib/enum_machine_contrib/edge.rb', line 5 def from @from end |
#mode ⇒ Object
Returns the value of attribute mode.
7 8 9 |
# File 'lib/enum_machine_contrib/edge.rb', line 7 def mode @mode end |
#to ⇒ Object
Returns the value of attribute to
5 6 7 |
# File 'lib/enum_machine_contrib/edge.rb', line 5 def to @to end |
Instance Method Details
#active? ⇒ Boolean
37 38 39 |
# File 'lib/enum_machine_contrib/edge.rb', line 37 def active? !dropped? end |
#dropped! ⇒ Object
41 42 43 44 45 46 |
# File 'lib/enum_machine_contrib/edge.rb', line 41 def dropped! self.mode = :dropped to.incoming_edges.delete(self) from.outcoming_edges.delete(self) end |
#inspect ⇒ Object
64 65 66 |
# File 'lib/enum_machine_contrib/edge.rb', line 64 def inspect "<Edge [#{mode}]#{'[resolved]' if resolved?} #{from.inspect} -> #{to.inspect}>" end |
#resolved! ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/enum_machine_contrib/edge.rb', line 52 def resolved! @resolved = true to.incoming_edges.each do |edge| edge.dropped! unless edge == self end to.outcoming_edges.detect { |edge| edge.to == from }&.dropped! to.resolved! end |
#resolved? ⇒ Boolean
48 49 50 |
# File 'lib/enum_machine_contrib/edge.rb', line 48 def resolved? @resolved == true end |