Class: Philiprehberger::StateMachine::ParallelStateSet

Inherits:
Object
  • Object
show all
Defined in:
lib/philiprehberger/state_machine/parallel_state.rb

Overview

Manages parallel (concurrent) substates that can be active simultaneously.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParallelStateSet

Returns a new instance of ParallelStateSet.



10
11
12
# File 'lib/philiprehberger/state_machine/parallel_state.rb', line 10

def initialize
  @active = []
end

Instance Attribute Details

#activeArray<Symbol> (readonly)

Returns the active substates.

Returns:

  • (Array<Symbol>)

    the active substates



8
9
10
# File 'lib/philiprehberger/state_machine/parallel_state.rb', line 8

def active
  @active
end

Instance Method Details

#activate(states) ⇒ Object

Activate a set of parallel substates.

Parameters:

  • states (Array<Symbol>)


17
18
19
# File 'lib/philiprehberger/state_machine/parallel_state.rb', line 17

def activate(states)
  @active = states.dup
end

#active?(state) ⇒ Boolean

Check if a specific substate is active.

Parameters:

  • state (Symbol)

Returns:

  • (Boolean)


30
31
32
# File 'lib/philiprehberger/state_machine/parallel_state.rb', line 30

def active?(state)
  @active.include?(state)
end

#any_active?Boolean

Check if any parallel substates are active.

Returns:

  • (Boolean)


37
38
39
# File 'lib/philiprehberger/state_machine/parallel_state.rb', line 37

def any_active?
  !@active.empty?
end

#deactivateObject

Deactivate all parallel substates.



22
23
24
# File 'lib/philiprehberger/state_machine/parallel_state.rb', line 22

def deactivate
  @active = []
end