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 included from Enumerable
Methods inherited from Iterator
#method_missing, #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.
288 289 290 291 292 293 |
# File 'lib/puppet/pops/types/iterable.rb', line 288 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.
295 296 297 |
# File 'lib/puppet/pops/types/iterable.rb', line 295 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.
299 300 301 302 303 304 305 306 307 |
# File 'lib/puppet/pops/types/iterable.rb', line 299 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.
309 310 311 312 |
# File 'lib/puppet/pops/types/iterable.rb', line 309 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.
314 315 316 |
# File 'lib/puppet/pops/types/iterable.rb', line 314 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.
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/puppet/pops/types/iterable.rb', line 318 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.
335 336 337 |
# File 'lib/puppet/pops/types/iterable.rb', line 335 def unbounded? false end |