Class: TEF::ProgramSelection::SequenceCollection
- Inherits:
-
Object
- Object
- TEF::ProgramSelection::SequenceCollection
- Defined in:
- lib/tef/ProgramSelection/SequenceCollection.rb
Overview
Sheet Sequence collection
This class is meant as a convenient container for Sequencing::Sheets. It automatically registers used IDs with the used Selector, and is also responsible for easily registering ProgramSheets.
Instance Attribute Summary collapse
-
#sheet_opts ⇒ Hash<ID, Hash>
readonly
Options to pass to specific sheets when instantiating them.
Class Method Summary collapse
-
.current_collection ⇒ SequenceCollection
Last Collection that was instantiated.
- .current_collection=(n_collection) ⇒ Object
Instance Method Summary collapse
-
#[](key) ⇒ nil, ...
Sheet matching the given ID, or nil.
-
#[]=(key, n_program) ⇒ Object
Register a given program.
-
#initialize(program_selector, sequence_runner) ⇒ SequenceCollection
constructor
Initialize a collection.
-
#play(key) ⇒ Object
Start playing the Sequencing::Sheet matching the given ID.
Constructor Details
#initialize(program_selector, sequence_runner) ⇒ SequenceCollection
Initialize a collection.
The passed TEF::ProgramSelection::Selector is used to register Sheet IDs, while the passed Sequencing::Player is used to start playing Sheets when using #play
Will set current_collection to self
50 51 52 53 54 55 56 57 58 |
# File 'lib/tef/ProgramSelection/SequenceCollection.rb', line 50 def initialize(program_selector, sequence_runner) @program_selector = program_selector @sequence_runner = sequence_runner @known_programs = {} @sheet_opts = {} self.class.current_collection = self end |
Instance Attribute Details
#sheet_opts ⇒ Hash<ID, Hash> (readonly)
Returns Options to pass to specific sheets when instantiating them. Useful when re-using a Sequencing::Sheet for different programs.
18 19 20 |
# File 'lib/tef/ProgramSelection/SequenceCollection.rb', line 18 def sheet_opts @sheet_opts end |
Class Method Details
.current_collection ⇒ SequenceCollection
Returns Last Collection that was instantiated. Used by TEF::ProgramSelection to register itself.
23 24 25 |
# File 'lib/tef/ProgramSelection/SequenceCollection.rb', line 23 def self.current_collection @current_collection end |
.current_collection=(n_collection) ⇒ Object
26 27 28 |
# File 'lib/tef/ProgramSelection/SequenceCollection.rb', line 26 def self.current_collection=(n_collection) @current_collection = n_collection end |
Instance Method Details
#[](key) ⇒ nil, ...
Returns Sheet matching the given ID, or nil.
62 63 64 |
# File 'lib/tef/ProgramSelection/SequenceCollection.rb', line 62 def [](key) @known_programs[key] end |
#[]=(key, n_program) ⇒ Object
Register a given program.
73 74 75 76 |
# File 'lib/tef/ProgramSelection/SequenceCollection.rb', line 73 def []=(key, n_program) key = @program_selector.register_ID key @known_programs[key] = n_program end |
#play(key) ⇒ Object
Start playing the Sequencing::Sheet matching the given ID
This function will instantiate a new Sequencing::SheetSequence if the registered program was a ProgramSheet. It will pass the #sheet_opts matching its ID to the SheetSequence, and will additionally set the option’s :program_key value to the ID used here. This allows easy re-using of sheets by passing parameters via the sheet options.
The created sheet is then passed to Sequencing::Player#[]=, using either ProgramSheet#program_key or ‘default’ as key.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/tef/ProgramSelection/SequenceCollection.rb', line 90 def play(key) prog = @known_programs[key] return unless prog prog_key = prog.program_key if prog.is_a? ProgramSheet if prog.is_a? Sequencing::Sheet opts = @sheet_opts[key] || {} opts[:sheet] = prog opts[:program_key] = key prog = Sequencing::SheetSequence.new(Time.now(), 1, **opts) end prog_key ||= 'default' @sequence_runner[prog_key] = prog end |