Class: Puppet::Pops::Types::PIntegerType
- Inherits:
-
PNumericType
- Object
- TypedModelObject
- PAnyType
- PScalarType
- PNumericType
- Puppet::Pops::Types::PIntegerType
- Includes:
- Enumerable
- Defined in:
- lib/puppet/pops/types/types.rb
Constant Summary collapse
- DEFAULT =
PIntegerType.new(-Float::INFINITY)
Instance Method Summary collapse
-
#each ⇒ Object
Returns Enumerator if no block is given Returns nil if size is infinity (does not yield).
- #enumerable? ⇒ Boolean
- #generalize ⇒ Object
- #instance?(o) ⇒ Boolean
-
#range ⇒ Object
Returns the range as an array ordered so the smaller number is always first.
-
#size ⇒ Object
Returns Float.Infinity if one end of the range is unbound.
-
#to_size ⇒ PIntegerType
Returns a range where both to and from are positive numbers.
Methods inherited from PNumericType
#==, #from, #hash, #initialize, #numeric_from, #numeric_to, #to, #unbounded?
Methods inherited from PAnyType
#==, #assignable?, #callable?, #callable_args?, #hash, #kind_of_callable?, #simple_name, #to_s
Methods included from Visitable
Constructor Details
This class inherits a constructor from Puppet::Pops::Types::PNumericType
Instance Method Details
#each ⇒ Object
Returns Enumerator if no block is given Returns nil if size is infinity (does not yield)
521 522 523 524 525 526 527 |
# File 'lib/puppet/pops/types/types.rb', line 521 def each if block_given? enumerable? ? @from.upto(@to) { |x| yield x } : nil else to_enum end end |
#enumerable? ⇒ Boolean
495 496 497 |
# File 'lib/puppet/pops/types/types.rb', line 495 def enumerable? @from != -Float::INFINITY && @to != Float::INFINITY end |
#generalize ⇒ Object
499 500 501 |
# File 'lib/puppet/pops/types/types.rb', line 499 def generalize DEFAULT end |
#instance?(o) ⇒ Boolean
503 504 505 |
# File 'lib/puppet/pops/types/types.rb', line 503 def instance?(o) o.is_a?(Integer) && o >= numeric_from && o <= numeric_to end |
#range ⇒ Object
Returns the range as an array ordered so the smaller number is always first. The number may be Infinity or -Infinity.
515 516 517 |
# File 'lib/puppet/pops/types/types.rb', line 515 def range [@from, @to] end |
#size ⇒ Object
Returns Float.Infinity if one end of the range is unbound
508 509 510 511 |
# File 'lib/puppet/pops/types/types.rb', line 508 def size return Float::INFINITY if @from == -Float::INFINITY || @to == Float::INFINITY 1+(to-from).abs end |
#to_size ⇒ PIntegerType
Returns a range where both to and from are positive numbers. Negative numbers are converted to zero
532 533 534 |
# File 'lib/puppet/pops/types/types.rb', line 532 def to_size @from >= 0 ? self : PIntegerType.new(0, @to < 0 ? 0 : @to) end |