Class: Jsm::States
- Inherits:
-
Object
- Object
- Jsm::States
- Defined in:
- lib/jsm/states.rb
Overview
Jsm::States job is to collect all states
Instance Attribute Summary collapse
-
#list ⇒ Object
readonly
Returns the value of attribute list.
Instance Method Summary collapse
-
#add_state(state_name, params = {}) ⇒ Object
register new state into the list.
- #has_state?(state_name) ⇒ Boolean
-
#initialize ⇒ States
constructor
A new instance of States.
Constructor Details
#initialize ⇒ States
Returns a new instance of States.
6 7 8 |
# File 'lib/jsm/states.rb', line 6 def initialize @list = [] end |
Instance Attribute Details
#list ⇒ Object (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
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
22 23 24 |
# File 'lib/jsm/states.rb', line 22 def has_state?(state_name) list.any? { |state| state.name == state_name} end |