Class: Array
- Defined in:
- lib/musa-dsl/matrix/matrix.rb,
lib/musa-dsl/matrix/matrix.rb,
lib/musa-dsl/matrix/matrix.rb,
lib/musa-dsl/core-ext/arrayfy.rb,
lib/musa-dsl/core-ext/hashify.rb,
lib/musa-dsl/series/array-to-serie.rb,
lib/musa-dsl/neumas/array-to-neumas.rb,
lib/musa-dsl/neumas/array-to-neumas.rb,
lib/musa-dsl/neumas/array-to-neumas.rb,
lib/musa-dsl/core-ext/array-explode-ranges.rb
Instance Method Summary collapse
-
#arrayfy(size: nil, default: nil) ⇒ Array
Clones or cycles the array to achieve the target size, with nil replacement.
-
#condensed_matrices ⇒ Array<::Matrix>
Condenses matrices that share common boundary rows.
-
#explode_ranges ⇒ Array
Expands all Range objects in the array into their individual elements.
-
#hashify(keys: , default: nil) ⇒ Hash
Maps array elements to hash keys in order, consuming the array.
-
#indexes_of_values ⇒ Hash{Object => Array<Integer>}
Creates a hash mapping values to their indices in the array.
-
#n ⇒ Object
Short alias for
to_neumas. -
#neumas ⇒ Object
Alias for
to_neumas. -
#to_neumas ⇒ Serie, Neuma
Converts array elements to merged neuma series.
-
#to_p(time_dimension: , keep_time: nil) ⇒ Array<Musa::Datasets::P>
Converts an array of matrices to an array of P sequences.
-
#to_serie(of_series: nil, recursive: nil) ⇒ Serie
(also: #s)
Converts array to Serie.
Instance Method Details
#arrayfy(size: nil, default: nil) ⇒ Array
This method is added to Array via refinement. Requires using Musa::Extension::Arrayfy.
The cycling formula: array * (size / array.size + (size % array.size).zero? ? 0 : 1) ensures enough repetitions to reach target size.
Clones or cycles the array to achieve the target size, with nil replacement.
The cycling behavior multiplies the array enough times to reach or exceed the target size, then takes exactly the requested number of elements. Singleton class modules (like P, V dataset extensions) are preserved.
128 |
# File 'lib/musa-dsl/core-ext/arrayfy.rb', line 128 class ::Array; end |
#condensed_matrices ⇒ Array<::Matrix>
This method is added to Array via refinement. Requires using Musa::Extension::Matrix.
Condenses matrices that share common boundary rows.
This method merges matrices that have matching first or last rows, effectively connecting musical gestures that share endpoints. This is particularly useful for creating continuous trajectories from fragmented matrix segments.
The algorithm compares each matrix with all previously processed matrices, looking for matches at either the beginning or end of the row sequence. When a match is found, the matrices are merged.
153 |
# File 'lib/musa-dsl/matrix/matrix.rb', line 153 class ::Array; end |
#explode_ranges ⇒ Array
This method is added to Array via refinement. Requires using Musa::Extension::ExplodeRanges.
Expands all Range objects in the array into their individual elements.
Iterates through the array and converts any Range objects to their
constituent elements via to_a, leaving non-Range elements unchanged.
The result is a new flat array.
70 |
# File 'lib/musa-dsl/core-ext/array-explode-ranges.rb', line 70 class ::Array; end |
#hashify(keys: , default: nil) ⇒ Hash
This method is added to Array via refinement. Requires using Musa::Extension::Hashify.
Maps array elements to hash keys in order, consuming the array.
Elements are assigned to keys sequentially. If the array has fewer elements than keys, remaining keys get nil (or default). The array is cloned before consumption, so the original is unchanged.
137 |
# File 'lib/musa-dsl/core-ext/hashify.rb', line 137 class ::Array; end |
#indexes_of_values ⇒ Hash{Object => Array<Integer>}
This method is added to Array via refinement. Requires using Musa::Extension::Matrix.
Creates a hash mapping values to their indices in the array.
This method scans the array and builds an inverted index where each unique value maps to an array of positions where it appears.
103 |
# File 'lib/musa-dsl/matrix/matrix.rb', line 103 class ::Array; end |
#n ⇒ Object
This method is added to Array via refinement. Requires using Musa::Extension::Neumas.
Short alias for to_neumas.
144 |
# File 'lib/musa-dsl/neumas/array-to-neumas.rb', line 144 class ::Array; end |
#neumas ⇒ Object
This method is added to Array via refinement. Requires using Musa::Extension::Neumas.
Alias for to_neumas.
134 |
# File 'lib/musa-dsl/neumas/array-to-neumas.rb', line 134 class ::Array; end |
#to_neumas ⇒ Serie, Neuma
This method is added to Array via refinement. Requires using Musa::Extension::Neumas.
Converts array elements to merged neuma series.
- Single element: Returns converted element directly
- Multiple elements: Returns MERGE of all converted elements
Each element is converted based on its type:
- String → parsed as neuma notation
- Neuma::Serie → used directly
- Neuma::Parallel → wrapped in series
124 |
# File 'lib/musa-dsl/neumas/array-to-neumas.rb', line 124 class ::Array; end |
#to_p(time_dimension: , keep_time: nil) ⇒ Array<Musa::Datasets::P>
This method is added to Array via refinement. Requires using Musa::Extension::Matrix.
Converts an array of matrices to an array of P sequences.
This method processes each matrix in the array, first condensing matrices that share common endpoints, then converting each resulting matrix to P (point sequence) format.
128 |
# File 'lib/musa-dsl/matrix/matrix.rb', line 128 class ::Array; end |
#to_serie(of_series: nil, recursive: nil) ⇒ Serie Also known as: s
Converts array to Serie.
Three conversion modes:
- Basic: Direct conversion to serie
- of_series: Each element of the array becomes a new serie (for array of arrays)
- recursive: Recursive conversion of nested arrays
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/musa-dsl/series/array-to-serie.rb', line 34 def to_serie(of_series: nil, recursive: nil) of_series ||= false recursive ||= false raise ArgumentError, 'Cannot convert to serie of_series and recursive simultaneously' if recursive && of_series if recursive Musa::Series::Constructors.S(*(collect { |_| _.is_a?(Array) ? _.to_serie(recursive: true) : _ })) elsif of_series Musa::Series::Constructors.S(*(collect { |_| Musa::Series::Constructors.S(*_) })) else Musa::Series::Constructors.S(*self) end end |