Class: Lab42::StateMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/lab42/state_machine.rb,
lib/lab42/state_machine/dsl.rb,
lib/lab42/state_machine/state.rb,
lib/lab42/state_machine/version.rb

Defined Under Namespace

Classes: DSL, State

Constant Summary collapse

VERSION =
"0.3.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#currentObject

Returns the value of attribute current.



6
7
8
# File 'lib/lab42/state_machine.rb', line 6

def current
  @current
end

#designationObject (readonly)

Returns the value of attribute designation.



7
8
9
# File 'lib/lab42/state_machine.rb', line 7

def designation
  @designation
end

#inputObject

Returns the value of attribute input.



6
7
8
# File 'lib/lab42/state_machine.rb', line 6

def input
  @input
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/lab42/state_machine.rb', line 7

def options
  @options
end

#outputObject

Returns the value of attribute output.



6
7
8
# File 'lib/lab42/state_machine.rb', line 6

def output
  @output
end

#statesObject (readonly)

Returns the value of attribute states.



7
8
9
# File 'lib/lab42/state_machine.rb', line 7

def states
  @states
end

Instance Method Details

#add(state, trigger, action, new_state = nil) ⇒ Object



10
11
12
13
# File 'lib/lab42/state_machine.rb', line 10

def add(state, trigger, action, new_state=nil)
  s = states[state]
  s.add(trigger, action, new_state)
end

#run(accumulator = nil, input = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/lab42/state_machine.rb', line 15

def run(accumulator=nil, input=nil)
  if input
    @input = input
    @input = input.enum_for(:each) unless Enumerator === input
  end
  loop do
    accumulator = _transition(accumulator)
  end
  accumulator
end