Class: Puppet::Pops::Types::PNumericType
- Inherits:
-
PScalarType
- Object
- TypedModelObject
- PAnyType
- PScalarType
- Puppet::Pops::Types::PNumericType
- Defined in:
- lib/puppet/pops/types/types.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT =
PNumericType.new(-Float::INFINITY)
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#from ⇒ Float, Integer
Returns the lower bound of the numeric range or ‘nil` if no lower bound is set.
- #hash ⇒ Object
-
#initialize(from, to = Float::INFINITY) ⇒ PNumericType
constructor
A new instance of PNumericType.
- #instance?(o) ⇒ Boolean
-
#numeric_from ⇒ Float, Integer
Same as #from but will return ‘-Float::Infinity` instead of `nil` if no lower bound is set.
-
#numeric_to ⇒ Float, Integer
Same as #to but will return ‘Float::Infinity` instead of `nil` if no lower bound is set.
-
#to ⇒ Float, Integer
Returns the upper bound of the numeric range or ‘nil` if no upper bound is set.
- #unbounded? ⇒ Boolean
Methods inherited from PAnyType
#assignable?, #callable?, #callable_args?, #enumerable?, #generalize, #kind_of_callable?, #simple_name, #to_s
Methods included from Visitable
Constructor Details
#initialize(from, to = Float::INFINITY) ⇒ PNumericType
Returns a new instance of PNumericType.
423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/puppet/pops/types/types.rb', line 423 def initialize(from, to = Float::INFINITY) from = -Float::INFINITY if from.nil? || from == :default to = Float::INFINITY if to.nil? || to == :default # Always create in right order if from <= to @from = from @to = to else @to = from @from = to end end |
Instance Method Details
#==(o) ⇒ Object
465 466 467 |
# File 'lib/puppet/pops/types/types.rb', line 465 def ==(o) self.class == o.class && @from == o.numeric_from && @to == o.numeric_to end |
#from ⇒ Float, Integer
Returns the lower bound of the numeric range or ‘nil` if no lower bound is set.
439 440 441 |
# File 'lib/puppet/pops/types/types.rb', line 439 def from @from == -Float::INFINITY ? nil : @from end |
#hash ⇒ Object
461 462 463 |
# File 'lib/puppet/pops/types/types.rb', line 461 def hash @from.hash * 31 + @to.hash end |
#instance?(o) ⇒ Boolean
469 470 471 |
# File 'lib/puppet/pops/types/types.rb', line 469 def instance?(o) o.is_a?(Numeric) && o >= @from && o <= @to end |
#numeric_from ⇒ Float, Integer
Same as #from but will return ‘-Float::Infinity` instead of `nil` if no lower bound is set.
451 452 453 |
# File 'lib/puppet/pops/types/types.rb', line 451 def numeric_from @from end |
#numeric_to ⇒ Float, Integer
Same as #to but will return ‘Float::Infinity` instead of `nil` if no lower bound is set.
457 458 459 |
# File 'lib/puppet/pops/types/types.rb', line 457 def numeric_to @to end |
#to ⇒ Float, Integer
Returns the upper bound of the numeric range or ‘nil` if no upper bound is set.
445 446 447 |
# File 'lib/puppet/pops/types/types.rb', line 445 def to @to == Float::INFINITY ? nil : @to end |
#unbounded? ⇒ Boolean
473 474 475 |
# File 'lib/puppet/pops/types/types.rb', line 473 def unbounded? @from == -Float::INFINITY && @to == Float::INFINITY end |