class Puppet::Pops::Types::PAbstractTimeDataType
Public Class Methods
@param from [AbstractTime] lower bound for this type. Nil or :default means unbounded @param to [AbstractTime] upper bound for this type. Nil or :default means unbounded
# File lib/puppet/pops/types/p_timespan_type.rb 6 def initialize(from, to = nil) 7 @from = convert_arg(from, true) 8 @to = convert_arg(to, false) 9 raise ArgumentError, "'from' must be less or equal to 'to'. Got (#{@from}, #{@to}" unless @from <= @to 10 end
Public Instance Methods
# File lib/puppet/pops/types/p_timespan_type.rb 93 def _assignable?(o, guard) 94 self.class == o.class && numeric_from <= o.numeric_from && numeric_to >= o.numeric_to 95 end
# File lib/puppet/pops/types/p_timespan_type.rb 57 def convert_arg(arg, min) 58 case arg 59 when impl_class 60 arg 61 when Hash 62 impl_class.from_hash(arg) 63 when nil, :default 64 min ? -Float::INFINITY : Float::INFINITY 65 when String 66 impl_class.parse(arg) 67 when Integer 68 impl_class.new(arg * Time::NSECS_PER_SEC) 69 when Float 70 impl_class.new(arg * Time::NSECS_PER_SEC) 71 else 72 raise ArgumentError, "Unable to create a #{impl_class.name} from a #{arg.class.name}" unless arg.nil? || arg == :default 73 nil 74 end 75 end
# File lib/puppet/pops/types/p_timespan_type.rb 49 def eql?(o) 50 self.class == o.class && @from == o.numeric_from && @to == o.numeric_to 51 end
Returns the lower bound of the numeric range or `nil` if no lower bound is set. @return [Float,Integer]
# File lib/puppet/pops/types/p_timespan_type.rb 23 def from 24 @from == -Float::INFINITY ? nil : @from 25 end
# File lib/puppet/pops/types/p_timespan_type.rb 45 def hash 46 @from.hash ^ @to.hash 47 end
Checks if this numeric range intersects with another
@param o [PNumericType] the range to compare with @return [Boolean] `true` if this range intersects with the other range @api public
# File lib/puppet/pops/types/p_timespan_type.rb 17 def intersect?(o) 18 self.class == o.class && !(@to < o.numeric_from || o.numeric_to < @from) 19 end
Concatenates this range with another range provided that the ranges intersect or are adjacent. When that's not the case, this method will return `nil`
@param o [PAbstractTimeDataType] the range to concatenate with this range @return [PAbstractTimeDataType,nil] the concatenated range or `nil` when the ranges were apart @api public
# File lib/puppet/pops/types/p_timespan_type.rb 83 def merge(o) 84 if intersect?(o) || adjacent?(o) 85 new_min = numeric_from <= o.numeric_from ? numeric_from : o.numeric_from 86 new_max = numeric_to >= o.numeric_to ? numeric_to : o.numeric_to 87 self.class.new(new_min, new_max) 88 else 89 nil 90 end 91 end
Same as from
but will return `-Float::Infinity` instead of `nil` if no lower bound is set. @return [Float,Integer]
# File lib/puppet/pops/types/p_timespan_type.rb 35 def numeric_from 36 @from 37 end
Same as to
but will return `Float::Infinity` instead of `nil` if no lower bound is set. @return [Float,Integer]
# File lib/puppet/pops/types/p_timespan_type.rb 41 def numeric_to 42 @to 43 end
Returns the upper bound of the numeric range or `nil` if no upper bound is set. @return [Float,Integer]
# File lib/puppet/pops/types/p_timespan_type.rb 29 def to 30 @to == Float::INFINITY ? nil : @to 31 end
# File lib/puppet/pops/types/p_timespan_type.rb 53 def unbounded? 54 @from == -Float::INFINITY && @to == Float::INFINITY 55 end