Class: Jsm::States

Inherits:
Object
  • Object
show all
Defined in:
lib/jsm/states.rb

Overview

Jsm::States job is to collect all states

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStates

Returns a new instance of States.



6
7
8
# File 'lib/jsm/states.rb', line 6

def initialize
  @list = []
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



3
4
5
# File 'lib/jsm/states.rb', line 3

def list
  @list
end

Instance Method Details

#add_state(state_name, params = {}) ⇒ Object

register new state into the list

Parameters:

  • state_name


12
13
14
15
16
17
18
19
20
# File 'lib/jsm/states.rb', line 12

def add_state(state_name, params = {})
  initial = params.fetch(:initial) { false }
  if !state_unique?(state_name)
    raise Jsm::NotUniqueStateError, "state #{state_name} has been defined"
  end

  state = create_state(state_name, initial)
  list.push(state)
end

#has_state?(state_name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/jsm/states.rb', line 22

def has_state?(state_name)
  list.any? { |state| state.name == state_name}
end