Class: Stamina::Automaton::Edge
- Inherits:
-
Object
- Object
- Stamina::Automaton::Edge
- Includes:
- Markable
- Defined in:
- lib/stamina-core/stamina/automaton/edge.rb
Overview
Automaton edge.
Instance Attribute Summary collapse
-
#automaton ⇒ Object
readonly
Returns the value of attribute automaton.
-
#from ⇒ Object
(also: #source)
readonly
Returns the value of attribute from.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#to ⇒ Object
(also: #target)
readonly
Returns the value of attribute to.
Instance Method Summary collapse
-
#<=>(o) ⇒ Object
Provides comparator of edges, based on the index in the automaton edge list.
-
#initialize(automaton, index, data, from, to) ⇒ Edge
constructor
Creates an edge.
-
#inspect ⇒ Object
Returns a string representation.
-
#symbol ⇒ Object
Returns edge symbol.
-
#symbol=(symbol) ⇒ Object
Sets edge symbol.
-
#to_s ⇒ Object
Returns a string representation.
Methods included from Markable
#[], #[]=, #data, #marks, #raw_data, #remove_mark
Constructor Details
#initialize(automaton, index, data, from, to) ⇒ Edge
Creates an edge.
Arguments:
-
automaton: parent automaton of the edge.
-
index: index of the edge in the edge list.
-
data: user data attached to this edge.
-
from: source state of the edge.
-
to: target state of the edge.
20 21 22 23 24 |
# File 'lib/stamina-core/stamina/automaton/edge.rb', line 20 def initialize(automaton, index, data, from, to) @automaton, @index = automaton, index @data = data @from, @to = from, to end |
Instance Attribute Details
#automaton ⇒ Object (readonly)
Returns the value of attribute automaton.
8 9 10 |
# File 'lib/stamina-core/stamina/automaton/edge.rb', line 8 def automaton @automaton end |
#from ⇒ Object (readonly) Also known as: source
Returns the value of attribute from.
8 9 10 |
# File 'lib/stamina-core/stamina/automaton/edge.rb', line 8 def from @from end |
#index ⇒ Object
Returns the value of attribute index.
8 9 10 |
# File 'lib/stamina-core/stamina/automaton/edge.rb', line 8 def index @index end |
#to ⇒ Object (readonly) Also known as: target
Returns the value of attribute to.
8 9 10 |
# File 'lib/stamina-core/stamina/automaton/edge.rb', line 8 def to @to end |
Instance Method Details
#<=>(o) ⇒ Object
Provides comparator of edges, based on the index in the automaton edge list. This method returns nil unless o is an Edge from the same automaton than self. Once again, this method has nothing to do with equality, it looks at an index and ID only.
46 47 48 49 50 |
# File 'lib/stamina-core/stamina/automaton/edge.rb', line 46 def <=>(o) return nil unless Edge===o return nil unless automaton===o.automaton return index <=> o.index end |
#inspect ⇒ Object
Returns a string representation
53 54 55 |
# File 'lib/stamina-core/stamina/automaton/edge.rb', line 53 def inspect 'e' << @index.to_s end |
#symbol ⇒ Object
Returns edge symbol.
27 28 29 |
# File 'lib/stamina-core/stamina/automaton/edge.rb', line 27 def symbol() @data[:symbol] end |
#symbol=(symbol) ⇒ Object
Sets edge symbol.
32 33 34 |
# File 'lib/stamina-core/stamina/automaton/edge.rb', line 32 def symbol=(symbol) @data[:symbol] = symbol end |
#to_s ⇒ Object
Returns a string representation
58 59 60 |
# File 'lib/stamina-core/stamina/automaton/edge.rb', line 58 def to_s 'e' << @index.to_s end |