Class: Stamina::Automaton::Edge

Inherits:
Object
  • Object
show all
Includes:
Markable
Defined in:
lib/stamina-core/stamina/automaton/edge.rb

Overview

Automaton edge.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#automatonObject (readonly)

Returns the value of attribute automaton.



8
9
10
# File 'lib/stamina-core/stamina/automaton/edge.rb', line 8

def automaton
  @automaton
end

#fromObject (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

#indexObject

Returns the value of attribute index.



8
9
10
# File 'lib/stamina-core/stamina/automaton/edge.rb', line 8

def index
  @index
end

#toObject (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

#inspectObject

Returns a string representation



53
54
55
# File 'lib/stamina-core/stamina/automaton/edge.rb', line 53

def inspect
  'e' << @index.to_s
end

#symbolObject

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_sObject

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