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.
323 324 325 326 327 328 329 |
# File 'lib/puppet/pops/types/iterable.rb', line 323 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.
331 332 333 |
# File 'lib/puppet/pops/types/iterable.rb', line 331 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.
335 336 337 338 339 340 341 342 343 |
# File 'lib/puppet/pops/types/iterable.rb', line 335 def next value = @current + @step_size if @step_size < 0 raise StopIteration if value < @range.from elsif value > @range.to raise StopIteration 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.
345 346 347 348 |
# File 'lib/puppet/pops/types/iterable.rb', line 345 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.
350 351 352 |
# File 'lib/puppet/pops/types/iterable.rb', line 350 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.
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/puppet/pops/types/iterable.rb', line 354 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.
371 372 373 |
# File 'lib/puppet/pops/types/iterable.rb', line 371 def unbounded? false end |