module Mealy
A Mealy
finite state machine.
For usage information please read {file:README.md README}.
Constants
- ANY
Wildcard for machine input tokens that match anything.
Public Class Methods
included(klass)
click to toggle source
@private Module.included hook. Resets the state transitions for a class
# File lib/mealy/dsl.rb, line 56 def self.included(klass) klass.class_eval { @transitions = Hash.new { Hash.new({}) } } klass.extend(DSL) end
Public Instance Methods
emit(token)
click to toggle source
emit tokens from the DSL
blocks @param token the emitted token
# File lib/mealy.rb, line 19 def emit(token) return unless @emit_runner @emit_runner.emit(token) end
execute(enum)
click to toggle source
Runs the Mealy
machine on the given input. @param enum [Enumerable] the input for the FSM @return the return value of the {Mealy::DSL#finish} block.
# File lib/mealy.rb, line 40 def execute(enum) Executer.new(self).run(enum) end
run(enum, &block)
click to toggle source
Runs the Mealy
machine on the given input. Outputs a stream of tokens by yielding each emitted token to the given block. @param enum [Enumerable] the input for the FSM @return [Enumerator] if no block is given @yieldparam emit The user token emitted by {#emit}.
# File lib/mealy.rb, line 29 def run(enum, &block) return to_enum(:run, enum) unless block_given? @emit_runner = Runner.new(self) @emit_runner.run(enum, &block) @emit_runner = nil end