Class: Stamina::Automaton::Edge

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

Overview

Automaton edge.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Markable

#[], #[]=, #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.



452
453
454
455
456
# File 'lib/stamina/automaton.rb', line 452

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.



440
441
442
# File 'lib/stamina/automaton.rb', line 440

def automaton
  @automaton
end

#fromObject (readonly) Also known as: source

Returns the value of attribute from.



440
441
442
# File 'lib/stamina/automaton.rb', line 440

def from
  @from
end

#indexObject

Returns the value of attribute index.



440
441
442
# File 'lib/stamina/automaton.rb', line 440

def index
  @index
end

#toObject (readonly) Also known as: target

Returns the value of attribute to.



440
441
442
# File 'lib/stamina/automaton.rb', line 440

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.



474
475
476
477
478
# File 'lib/stamina/automaton.rb', line 474

def <=>(o)
  return nil unless Edge===o
  return nil unless automaton===o.automaton
  return index <=> o.index
end

#inspectObject

Returns a string representation



481
482
483
# File 'lib/stamina/automaton.rb', line 481

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

#symbolObject

Returns edge symbol.



459
# File 'lib/stamina/automaton.rb', line 459

def symbol() @data[:symbol] end

#symbol=(symbol) ⇒ Object

Sets edge symbol.



462
# File 'lib/stamina/automaton.rb', line 462

def symbol=(symbol) @data[:symbol]=symbol end

#to_sObject

Returns a string representation



486
487
488
# File 'lib/stamina/automaton.rb', line 486

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