Class: SpecArray
Overview
This helper class encapsulates an array of flex array spec components.
Instance Attribute Summary collapse
-
#spec_count ⇒ Object
readonly
The number of elements defined by this array specification.
Instance Method Summary collapse
-
#enlarge(growth) ⇒ Object
Enlarge the flex array along its first dimension.
-
#initialize(array_specs) ⇒ SpecArray
constructor
Create a flex array specification.
-
#transposed? ⇒ Boolean
Is this array specification transposed in any way?.
Methods inherited from Array
#array_data, #array_specs, #limits, #to_flex_array, #to_index_range
Constructor Details
#initialize(array_specs) ⇒ SpecArray
Create a flex array specification.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/flex_array/spec_array.rb', line 11 def initialize(array_specs) super(0) @spec_count = 1 #Parse the array limits. array_specs.reverse_each do |spec| self.insert(0, spec.to_spec_component(@spec_count)) @spec_count *= self[0].span end self end |
Instance Attribute Details
#spec_count ⇒ Object (readonly)
The number of elements defined by this array specification.
5 6 7 |
# File 'lib/flex_array/spec_array.rb', line 5 def spec_count @spec_count end |
Instance Method Details
#enlarge(growth) ⇒ Object
Enlarge the flex array along its first dimension.
37 38 39 40 41 42 |
# File 'lib/flex_array/spec_array.rb', line 37 def enlarge(growth) self[0].enlarge(growth) #Compute the new size. @spec_count = self.inject(1) {|product, element| product*element.span} end |
#transposed? ⇒ Boolean
Is this array specification transposed in any way?
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/flex_array/spec_array.rb', line 25 def transposed? check = 1 self.reverse_each do |component| return true unless check == component.stride check *= component.span end false end |