Class: FiniteState::State

Inherits:
Object
  • Object
show all
Defined in:
lib/finite_state/state.rb

Overview

Represents a State within an Automaton

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ State

Initializes a new State with a name and optional parameters

Attributes

  • name - the name of the State

  • options - a Hash with options

Options

  • :is_start - a boolean (true if the state is a start state)

  • :is_end - a boolean (true if the state is an end state)

Example

name    = "s0"
options = { :is_start => true }
state   = State.new(name, options)

state.name   # => "s0"
state.start? # => true
state.end?   # => false

29
30
31
32
# File 'lib/finite_state/state.rb', line 29

def initialize(name, options = {})
  @name    = name
  @options = normalize_options(options)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


5
6
7
# File 'lib/finite_state/state.rb', line 5

def name
  @name
end

Instance Method Details

#end?Boolean

Returns true if the state is an end state


40
41
42
# File 'lib/finite_state/state.rb', line 40

def end?
  @options[:is_end]
end

#start?Boolean

Returns true if the state is a start state


35
36
37
# File 'lib/finite_state/state.rb', line 35

def start?
  @options[:is_start]
end