Class: NxtStateMachine::State
- Inherits:
-
Object
- Object
- NxtStateMachine::State
- Includes:
- Comparable
- Defined in:
- lib/nxt_state_machine/state.rb
Instance Attribute Summary collapse
-
#enum ⇒ Object
Returns the value of attribute enum.
-
#index ⇒ Object
Returns the value of attribute index.
-
#initial ⇒ Object
Returns the value of attribute initial.
-
#options ⇒ Object
Returns the value of attribute options.
-
#state_machine ⇒ Object
Returns the value of attribute state_machine.
-
#transitions ⇒ Object
Returns the value of attribute transitions.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #events ⇒ Object
- #first? ⇒ Boolean
-
#initialize(enum, state_machine, **opts) ⇒ State
constructor
A new instance of State.
- #last? ⇒ Boolean
- #next ⇒ Object
- #previous ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(enum, state_machine, **opts) ⇒ State
Returns a new instance of State.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/nxt_state_machine/state.rb', line 5 def initialize(enum, state_machine, **opts) @enum = enum @state_machine = state_machine @initial = opts.delete(:initial) @transitions = [] @options = opts.with_indifferent_access @index = opts.fetch(:index) ensure_index_not_occupied end |
Instance Attribute Details
#enum ⇒ Object
Returns the value of attribute enum.
16 17 18 |
# File 'lib/nxt_state_machine/state.rb', line 16 def enum @enum end |
#index ⇒ Object
Returns the value of attribute index.
16 17 18 |
# File 'lib/nxt_state_machine/state.rb', line 16 def index @index end |
#initial ⇒ Object
Returns the value of attribute initial.
16 17 18 |
# File 'lib/nxt_state_machine/state.rb', line 16 def initial @initial end |
#options ⇒ Object
Returns the value of attribute options.
16 17 18 |
# File 'lib/nxt_state_machine/state.rb', line 16 def @options end |
#state_machine ⇒ Object
Returns the value of attribute state_machine.
16 17 18 |
# File 'lib/nxt_state_machine/state.rb', line 16 def state_machine @state_machine end |
#transitions ⇒ Object
Returns the value of attribute transitions.
16 17 18 |
# File 'lib/nxt_state_machine/state.rb', line 16 def transitions @transitions end |
Instance Method Details
#<=>(other) ⇒ Object
44 45 46 |
# File 'lib/nxt_state_machine/state.rb', line 44 def <=>(other) index <=> other.index end |
#events ⇒ Object
40 41 42 |
# File 'lib/nxt_state_machine/state.rb', line 40 def events state_machine.events_for_state(enum) end |
#first? ⇒ Boolean
36 37 38 |
# File 'lib/nxt_state_machine/state.rb', line 36 def first? sorted_states.first.index == index end |
#last? ⇒ Boolean
32 33 34 |
# File 'lib/nxt_state_machine/state.rb', line 32 def last? sorted_states.last.index == index end |
#next ⇒ Object
27 28 29 30 |
# File 'lib/nxt_state_machine/state.rb', line 27 def next current_index = sorted_states.index { |state| state.index == index } sorted_states[(current_index + 1) % sorted_states.size] end |
#previous ⇒ Object
22 23 24 25 |
# File 'lib/nxt_state_machine/state.rb', line 22 def previous current_index = sorted_states.index { |state| state.index == index } sorted_states[(current_index - 1) % sorted_states.size] end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/nxt_state_machine/state.rb', line 18 def to_s enum.to_s end |