Class: StateMachina::StatesCollection
- Inherits:
-
Object
- Object
- StateMachina::StatesCollection
- Includes:
- Enumerable
- Defined in:
- lib/state_machina/states_collection.rb
Instance Method Summary collapse
- #before(state_name) ⇒ Object
- #before_inclusive(state_name) ⇒ Object
- #between(from_state_name, to_state_name) ⇒ Object
- #between_inclusive(from_state_name, to_state_name) ⇒ Object
- #each(&block) ⇒ Object
- #find_by_name(state_name) ⇒ Object
-
#initialize(states) ⇒ StatesCollection
constructor
A new instance of StatesCollection.
- #past(state_name) ⇒ Object
- #past_inclusive(state_name) ⇒ Object
Constructor Details
#initialize(states) ⇒ StatesCollection
Returns a new instance of StatesCollection.
5 6 7 |
# File 'lib/state_machina/states_collection.rb', line 5 def initialize(states) @states = states end |
Instance Method Details
#before(state_name) ⇒ Object
23 24 25 |
# File 'lib/state_machina/states_collection.rb', line 23 def before(state_name) to_a[..(index_by_name(state_name) - 1)] end |
#before_inclusive(state_name) ⇒ Object
27 28 29 |
# File 'lib/state_machina/states_collection.rb', line 27 def before_inclusive(state_name) to_a[..index_by_name(state_name)] end |
#between(from_state_name, to_state_name) ⇒ Object
39 40 41 |
# File 'lib/state_machina/states_collection.rb', line 39 def between(from_state_name, to_state_name) to_a[index_by_name(from_state_name)...index_by_name(to_state_name)] end |
#between_inclusive(from_state_name, to_state_name) ⇒ Object
43 44 45 |
# File 'lib/state_machina/states_collection.rb', line 43 def between_inclusive(from_state_name, to_state_name) to_a[index_by_name(from_state_name)..index_by_name(to_state_name)] end |
#each(&block) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/state_machina/states_collection.rb', line 9 def each(&block) if block_given? @states.each(&block) else to_enum(:each) end end |
#find_by_name(state_name) ⇒ Object
17 18 19 20 21 |
# File 'lib/state_machina/states_collection.rb', line 17 def find_by_name(state_name) find do |state| state.name == state_name.to_s end end |
#past(state_name) ⇒ Object
31 32 33 |
# File 'lib/state_machina/states_collection.rb', line 31 def past(state_name) to_a[(index_by_name(state_name) + 1)..] end |
#past_inclusive(state_name) ⇒ Object
35 36 37 |
# File 'lib/state_machina/states_collection.rb', line 35 def past_inclusive(state_name) to_a[index_by_name(state_name)..] end |