class SpecComponent

This helper class encapsulates a single component of the flex array spec.

Attributes

range[R]

The range of acceptable values for this limit.

stride[R]

The stride of this array dimension. That is, for each step in this dimension, how many steps are required in the low level array?

Public Class Methods

new(range, stride) click to toggle source

Create a limits component from its constituent data.

# File lib/flex_array/spec_component.rb, line 12
def initialize(range, stride)
  @range, @stride = range, stride
end

Public Instance Methods

==(other) click to toggle source

Limits are equal if their ranges are equal.

# File lib/flex_array/spec_component.rb, line 22
def ==(other)
  @range == other.range
end
===(value) click to toggle source

Forward '=== value' to the range.

# File lib/flex_array/spec_component.rb, line 17
def ===(value)
  @range === value
end
each(&block) click to toggle source

Forward 'each' and the block to the range.

# File lib/flex_array/spec_component.rb, line 37
def each(&block)
  @range.each(&block)
end
enlarge(growth) click to toggle source

Enlarge the range of this spec by the growth term.

# File lib/flex_array/spec_component.rb, line 51
def enlarge(growth)
  if @range.none?
    @range = 0...growth
  else
    @range = (@range.min)..(@range.max + growth)
  end
end
index_step(index) click to toggle source

Compute the step required for the index value.

# File lib/flex_array/spec_component.rb, line 60
def index_step(index)
  (index - @range.min) * @stride
end
max() click to toggle source

Forward 'max' to the range.

# File lib/flex_array/spec_component.rb, line 32
def max
  @range.max
end
min() click to toggle source

Forward 'min' to the range.

# File lib/flex_array/spec_component.rb, line 27
def min
  @range.min
end
span() click to toggle source

Compute the span of indexes in this limit component.

# File lib/flex_array/spec_component.rb, line 42
def span
  if @range.none?
    0
  else
    @range.max - @range.min + 1
  end
end