Class: SpecArray

Inherits:
Array show all
Defined in:
lib/flex_array/spec_array.rb

Overview

This helper class encapsulates an array of flex array spec components.

Instance Attribute Summary collapse

Instance Method Summary collapse

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.
Parameters

  • array_specs - The specification of the flex array subscript limits.

These can either be an array of containing integers, in which case
the limits are 0...n or they can be ranges, in which case the
limits are those of the range.


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/flex_array/spec_array.rb', line 15

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_countObject (readonly)

The number of elements defined by this array specification.



4
5
6
# File 'lib/flex_array/spec_array.rb', line 4

def spec_count
  @spec_count
end

Instance Method Details

#enlarge(growth) ⇒ Object

Enlarge the flex array along its first dimension.



41
42
43
44
45
46
# File 'lib/flex_array/spec_array.rb', line 41

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?



29
30
31
32
33
34
35
36
37
38
# File 'lib/flex_array/spec_array.rb', line 29

def transposed?
  check = 1

  self.reverse_each do |component|
    return true unless check == component.stride
    check *= component.span
  end

  false
end