Class: Fae::State
- Inherits:
-
Object
- Object
- Fae::State
- Defined in:
- lib/fae/state.rb
Overview
A state in the state diagram.
Instance Attribute Summary collapse
-
#accepting ⇒ Object
Returns the value of attribute accepting.
-
#name ⇒ Object
Returns the value of attribute name.
-
#paths ⇒ Object
Returns the value of attribute paths.
Instance Method Summary collapse
-
#evaluate(string, fa) ⇒ Object
Evaluates a string at this state, and passes the next string to the next state.
-
#initialize(name, paths, accepting) ⇒ State
constructor
Creates a new state instance.
Constructor Details
#initialize(name, paths, accepting) ⇒ State
Creates a new state instance.
14 15 16 17 18 |
# File 'lib/fae/state.rb', line 14 def initialize(name, paths, accepting) @name = name @paths = paths @accepting = accepting end |
Instance Attribute Details
#accepting ⇒ Object
Returns the value of attribute accepting.
5 6 7 |
# File 'lib/fae/state.rb', line 5 def accepting @accepting end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/fae/state.rb', line 5 def name @name end |
#paths ⇒ Object
Returns the value of attribute paths.
5 6 7 |
# File 'lib/fae/state.rb', line 5 def paths @paths end |
Instance Method Details
#evaluate(string, fa) ⇒ Object
Evaluates a string at this state, and passes the next string to the next state.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fae/state.rb', line 24 def evaluate(string, fa) output = "" if (string.first.empty?) output << "#{@name} (#{@accepting ? 'accepting'.colorize(:green) : 'not accepting'.colorize(:red)}) " return { :output => output, :accepting => @accepting } end output << "#{@name} #{'->'.colorize(:light_black)} " next_state = fa.get_state(paths[string.first.to_sym]) next_string = string.shift_left result = next_state.evaluate(next_string, fa) output << result[:output] return { :output => output, :accepting => result[:accepting] } end |