Class: EnumMachineContrib::Vertex
- Inherits:
-
Struct
- Object
- Struct
- EnumMachineContrib::Vertex
- Defined in:
- lib/enum_machine_contrib/vertex.rb
Constant Summary collapse
- VERTEX_MODES =
rubocop:disable Lint/ConstantDefinitionInBlock
%i[pending dropped combined cycled].freeze
Instance Attribute Summary collapse
-
#incoming_edges ⇒ Object
readonly
Returns the value of attribute incoming_edges.
-
#level ⇒ Object
Returns the value of attribute level.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#outcoming_edges ⇒ Object
readonly
Returns the value of attribute outcoming_edges.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #dropped! ⇒ Object
- #edge_to(to_vertex) ⇒ Object
-
#initialize(value) ⇒ Vertex
constructor
A new instance of Vertex.
- #inspect ⇒ Object
- #resolved! ⇒ Object
- #resolved? ⇒ Boolean
Constructor Details
Instance Attribute Details
#incoming_edges ⇒ Object (readonly)
Returns the value of attribute incoming_edges.
8 9 10 |
# File 'lib/enum_machine_contrib/vertex.rb', line 8 def incoming_edges @incoming_edges end |
#level ⇒ Object
Returns the value of attribute level.
7 8 9 |
# File 'lib/enum_machine_contrib/vertex.rb', line 7 def level @level end |
#mode ⇒ Object
Returns the value of attribute mode.
7 8 9 |
# File 'lib/enum_machine_contrib/vertex.rb', line 7 def mode @mode end |
#outcoming_edges ⇒ Object (readonly)
Returns the value of attribute outcoming_edges.
8 9 10 |
# File 'lib/enum_machine_contrib/vertex.rb', line 8 def outcoming_edges @outcoming_edges end |
#value ⇒ Object
Returns the value of attribute value
5 6 7 |
# File 'lib/enum_machine_contrib/vertex.rb', line 5 def value @value end |
Class Method Details
.replace!(replacing_vertexes) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/enum_machine_contrib/vertex.rb', line 70 def self.replace!(replacing_vertexes) new_vertex = Vertex[replacing_vertexes.flat_map(&:value)] replacing_vertexes.each do |replacing_vertex| replacing_vertex.incoming_edges.each do |edge| next if replacing_vertexes.include?(edge.from) edge.from.edge_to(new_vertex) end replacing_vertex.outcoming_edges.filter_map do |edge| next if replacing_vertexes.include?(edge.to) new_vertex.edge_to(edge.to) end replacing_vertex.dropped! end new_vertex end |
Instance Method Details
#active? ⇒ Boolean
40 41 42 |
# File 'lib/enum_machine_contrib/vertex.rb', line 40 def active? !dropped? end |
#dropped! ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/enum_machine_contrib/vertex.rb', line 52 def dropped! return if dropped? self.mode = :dropped incoming_edges.each(&:dropped!) outcoming_edges.each(&:dropped!) end |
#edge_to(to_vertex) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/enum_machine_contrib/vertex.rb', line 61 def edge_to(to_vertex) new_edge = Edge.new(self, to_vertex) outcoming_edges.add(new_edge) to_vertex.incoming_edges.add(new_edge) new_edge end |
#inspect ⇒ Object
92 93 94 |
# File 'lib/enum_machine_contrib/vertex.rb', line 92 def inspect "<Vertex [#{mode}]#{'[resolved]' if resolved?} value=#{value || 'nil'}>" end |
#resolved! ⇒ Object
44 45 46 |
# File 'lib/enum_machine_contrib/vertex.rb', line 44 def resolved! @resolved = true end |
#resolved? ⇒ Boolean
48 49 50 |
# File 'lib/enum_machine_contrib/vertex.rb', line 48 def resolved? @resolved == true end |