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?, #callable_with?, #check_self_recursion, #create, #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.
782 783 784 785 786 787 788 |
# File 'lib/puppet/pops/types/types.rb', line 782 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
827 828 829 |
# File 'lib/puppet/pops/types/types.rb', line 827 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.
801 802 803 |
# File 'lib/puppet/pops/types/types.rb', line 801 def from @from == -Float::INFINITY ? nil : @from end |
#hash ⇒ Object
823 824 825 |
# File 'lib/puppet/pops/types/types.rb', line 823 def hash @from.hash ^ @to.hash end |
#instance?(o, guard = nil) ⇒ Boolean
831 832 833 |
# File 'lib/puppet/pops/types/types.rb', line 831 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
795 796 797 |
# File 'lib/puppet/pops/types/types.rb', line 795 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.
813 814 815 |
# File 'lib/puppet/pops/types/types.rb', line 813 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.
819 820 821 |
# File 'lib/puppet/pops/types/types.rb', line 819 def numeric_to @to end |
#to ⇒ Float, Integer
Returns the upper bound of the numeric range or ‘nil` if no upper bound is set.
807 808 809 |
# File 'lib/puppet/pops/types/types.rb', line 807 def to @to == Float::INFINITY ? nil : @to end |
#unbounded? ⇒ Boolean
835 836 837 |
# File 'lib/puppet/pops/types/types.rb', line 835 def unbounded? @from == -Float::INFINITY && @to == Float::INFINITY end |