Module: Driskell::Listen::FSM::ClassMethods
- Defined in:
- lib/driskell-listen/fsm.rb
Instance Method Summary collapse
-
#default_state(new_default = nil) ⇒ Object
Obtain or set the default state Passing a state name sets the default state.
-
#state(*args, &block) ⇒ Object
Declare an FSM state and optionally provide a callback block to fire Options: * to: a state or array of states this state can transition to.
-
#states ⇒ Object
Obtain the valid states for this FSM.
Instance Method Details
#default_state(new_default = nil) ⇒ Object
Obtain or set the default state Passing a state name sets the default state
14 15 16 17 18 19 20 |
# File 'lib/driskell-listen/fsm.rb', line 14 def default_state(new_default = nil) if new_default @default_state = new_default.to_sym else defined?(@default_state) ? @default_state : DEFAULT_STATE end end |
#state(*args, &block) ⇒ Object
Declare an FSM state and optionally provide a callback block to fire Options:
-
to: a state or array of states this state can transition to
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/driskell-listen/fsm.rb', line 30 def state(*args, &block) if args.last.is_a? Hash # Stringify keys :/ = args.pop.each_with_object({}) { |(k, v), h| h[k.to_s] = v } else = {} end args.each do |name| name = name.to_sym default_state name if ['default'] states[name] = State.new(name, ['to'], &block) end end |
#states ⇒ Object
Obtain the valid states for this FSM
23 24 25 |
# File 'lib/driskell-listen/fsm.rb', line 23 def states @states ||= {} end |