Class: Puppet::Pops::Types::PAbstractRangeType
- Inherits:
-
PScalarType
- Object
- TypedModelObject
- PAnyType
- PScalarType
- Puppet::Pops::Types::PAbstractRangeType
- Defined in:
- lib/puppet/pops/types/types.rb
Overview
Abstract class that encapsulates behavior common to PNumericType and PAbstractTimeDataType
Direct Known Subclasses
Constant Summary
Constants inherited from PScalarType
Puppet::Pops::Types::PScalarType::DEFAULT
Constants inherited from PAnyType
Puppet::Pops::Types::PAnyType::DEFAULT
Instance Method Summary collapse
- #eql?(o) ⇒ Boolean
-
#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) ⇒ PAbstractRangeType
constructor
A new instance of PAbstractRangeType.
- #instance?(o, guard = nil) ⇒ Boolean
-
#intersect?(o) ⇒ Boolean
Checks if this numeric range intersects with another.
-
#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 PScalarType
Methods inherited from PAnyType
#==, #accept, #assignable?, #callable?, #callable_args?, #check_self_recursion, #generalize, #iterable?, #iterable_type, #kind_of_callable?, #name, new_function, #new_function, #normalize, #really_instance?, register_ptype, #resolve, #simple_name, simple_name, #to_alias_expanded_s, #to_s
Methods inherited from TypedModelObject
_ptype, create_ptype, register_ptypes
Methods included from Visitable
Methods included from PuppetObject
Constructor Details
#initialize(from, to = Float::INFINITY) ⇒ PAbstractRangeType
Returns a new instance of PAbstractRangeType.
747 748 749 750 751 752 753 |
# File 'lib/puppet/pops/types/types.rb', line 747 def initialize(from, to = Float::INFINITY) from = -Float::INFINITY if from.nil? || from == :default to = Float::INFINITY if to.nil? || to == :default raise ArgumentError, "'from' must be less or equal to 'to'. Got (#{from}, #{to}" if from.is_a?(Numeric) && to.is_a?(Numeric) && from > to @from = from @to = to end |
Instance Method Details
#eql?(o) ⇒ Boolean
792 793 794 |
# File 'lib/puppet/pops/types/types.rb', line 792 def eql?(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.
766 767 768 |
# File 'lib/puppet/pops/types/types.rb', line 766 def from @from == -Float::INFINITY ? nil : @from end |
#hash ⇒ Object
788 789 790 |
# File 'lib/puppet/pops/types/types.rb', line 788 def hash @from.hash ^ @to.hash end |
#instance?(o, guard = nil) ⇒ Boolean
796 797 798 |
# File 'lib/puppet/pops/types/types.rb', line 796 def instance?(o, guard = nil) o.is_a?(Numeric) && o >= @from && o <= @to end |
#intersect?(o) ⇒ Boolean
Checks if this numeric range intersects with another
760 761 762 |
# File 'lib/puppet/pops/types/types.rb', line 760 def intersect?(o) self.class == o.class && !(@to < o.numeric_from || o.numeric_to < @from) end |
#numeric_from ⇒ Float, Integer
Same as #from but will return ‘-Float::Infinity` instead of `nil` if no lower bound is set.
778 779 780 |
# File 'lib/puppet/pops/types/types.rb', line 778 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.
784 785 786 |
# File 'lib/puppet/pops/types/types.rb', line 784 def numeric_to @to end |
#to ⇒ Float, Integer
Returns the upper bound of the numeric range or ‘nil` if no upper bound is set.
772 773 774 |
# File 'lib/puppet/pops/types/types.rb', line 772 def to @to == Float::INFINITY ? nil : @to end |
#unbounded? ⇒ Boolean
800 801 802 |
# File 'lib/puppet/pops/types/types.rb', line 800 def unbounded? @from == -Float::INFINITY && @to == Float::INFINITY end |