Class: SpecComponent
Overview
This helper class encapsulates a single component of the flex array spec.
Instance Attribute Summary collapse
-
#range ⇒ Object
readonly
The range of acceptable values for this limit.
-
#stride ⇒ Object
readonly
The stride of this array dimension.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Limits are equal if their ranges are equal.
-
#===(value) ⇒ Object
Forward ‘=== value’ to the range.
-
#each(&block) ⇒ Object
Forward ‘each’ and the block to the range.
-
#enlarge(growth) ⇒ Object
Enlarge the range of this spec by the growth term.
-
#index_step(index) ⇒ Object
Compute the step required for the index value.
-
#initialize(range, stride) ⇒ SpecComponent
constructor
Create a limits component from its constituent data.
-
#max ⇒ Object
Forward ‘max’ to the range.
-
#min ⇒ Object
Forward ‘min’ to the range.
-
#span ⇒ Object
Compute the span of indexes in this limit component.
Constructor Details
#initialize(range, stride) ⇒ SpecComponent
Create a limits component from its constituent data.
12 13 14 |
# File 'lib/flex_array/spec_component.rb', line 12 def initialize(range, stride) @range, @stride = range, stride end |
Instance Attribute Details
#range ⇒ Object (readonly)
The range of acceptable values for this limit.
5 6 7 |
# File 'lib/flex_array/spec_component.rb', line 5 def range @range end |
#stride ⇒ Object (readonly)
The stride of this array dimension. That is, for each step in this dimension, how many steps are required in the low level array?
9 10 11 |
# File 'lib/flex_array/spec_component.rb', line 9 def stride @stride end |
Instance Method Details
#==(other) ⇒ Object
Limits are equal if their ranges are equal.
22 23 24 |
# File 'lib/flex_array/spec_component.rb', line 22 def ==(other) @range == other.range end |
#===(value) ⇒ Object
Forward ‘=== value’ to the range.
17 18 19 |
# File 'lib/flex_array/spec_component.rb', line 17 def ===(value) @range === value end |
#each(&block) ⇒ Object
Forward ‘each’ and the block to the range.
37 38 39 |
# File 'lib/flex_array/spec_component.rb', line 37 def each(&block) @range.each(&block) end |
#enlarge(growth) ⇒ Object
Enlarge the range of this spec by the growth term.
51 52 53 54 55 56 57 |
# 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) ⇒ Object
Compute the step required for the index value.
60 61 62 |
# File 'lib/flex_array/spec_component.rb', line 60 def index_step(index) (index - @range.min) * @stride end |
#max ⇒ Object
Forward ‘max’ to the range.
32 33 34 |
# File 'lib/flex_array/spec_component.rb', line 32 def max @range.max end |
#min ⇒ Object
Forward ‘min’ to the range.
27 28 29 |
# File 'lib/flex_array/spec_component.rb', line 27 def min @range.min end |
#span ⇒ Object
Compute the span of indexes in this limit component.
42 43 44 45 46 47 48 |
# File 'lib/flex_array/spec_component.rb', line 42 def span if @range.none? 0 else @range.max - @range.min + 1 end end |