Class: Puppet::Pops::Types::IntegerRangeIterator Private
- Includes:
- Enumerable
- Defined in:
- lib/puppet/pops/types/iterable.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #element_type ⇒ Object private
-
#initialize(range, step = 1) ⇒ IntegerRangeIterator
constructor
private
A new instance of IntegerRangeIterator.
- #next ⇒ Object private
- #reverse_each(&block) ⇒ Object private
- #size ⇒ Object private
- #step_iterator(step) ⇒ Object private
- #unbounded? ⇒ Boolean private
Methods inherited from Iterator
#all?, #any?, #map, #method_missing, #reduce, #respond_to_missing?, #step, #to_s
Methods included from Iterable
asserted_iterable, #each, #hash_style?, on, #step, #to_a, unbounded?
Constructor Details
#initialize(range, step = 1) ⇒ IntegerRangeIterator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of IntegerRangeIterator.
314 315 316 317 318 319 |
# File 'lib/puppet/pops/types/iterable.rb', line 314 def initialize(range, step = 1) raise ArgumentError if step == 0 @range = range @step_size = step @current = (step < 0 ? range.to : range.from) - step end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Puppet::Pops::Types::Iterator
Instance Method Details
#element_type ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
321 322 323 |
# File 'lib/puppet/pops/types/iterable.rb', line 321 def element_type @range end |
#next ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
325 326 327 328 329 330 331 332 333 |
# File 'lib/puppet/pops/types/iterable.rb', line 325 def next value = @current + @step_size if @step_size < 0 raise StopIteration if value < @range.from else raise StopIteration if value > @range.to end @current = value end |
#reverse_each(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
335 336 337 338 |
# File 'lib/puppet/pops/types/iterable.rb', line 335 def reverse_each(&block) r = IntegerRangeIterator.new(@range, -@step_size) block_given? ? r.each(&block) : r end |
#size ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
340 341 342 |
# File 'lib/puppet/pops/types/iterable.rb', line 340 def size (@range.to - @range.from) / @step_size.abs end |
#step_iterator(step) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/puppet/pops/types/iterable.rb', line 344 def step_iterator(step) # The step iterator must use a range that has its logical end truncated at an even step boundary. This will # fulfil two objectives: # 1. The element_type method should not report excessive integers as possible numbers # 2. A reversed iterator must start at the correct number # range = @range step = @step_size * step mod = (range.to - range.from) % step if mod < 0 range = PIntegerType.new(range.from - mod, range.to) elsif mod > 0 range = PIntegerType.new(range.from, range.to - mod) end IntegerRangeIterator.new(range, step) end |
#unbounded? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
361 362 363 |
# File 'lib/puppet/pops/types/iterable.rb', line 361 def unbounded? false end |