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 7 def initialize(from, to = nil) 8 @from = convert_arg(from, true) 9 @to = convert_arg(to, false) 10 raise ArgumentError, "'from' must be less or equal to 'to'. Got (#{@from}, #{@to}" unless @from <= @to 11 end
Public Instance Methods
# File lib/puppet/pops/types/p_timespan_type.rb 94 def _assignable?(o, guard) 95 self.class == o.class && numeric_from <= o.numeric_from && numeric_to >= o.numeric_to 96 end
# File lib/puppet/pops/types/p_timespan_type.rb 58 def convert_arg(arg, min) 59 case arg 60 when impl_class 61 arg 62 when Hash 63 impl_class.from_hash(arg) 64 when nil, :default 65 min ? -Float::INFINITY : Float::INFINITY 66 when String 67 impl_class.parse(arg) 68 when Integer 69 impl_class.new(arg * Time::NSECS_PER_SEC) 70 when Float 71 impl_class.new(arg * Time::NSECS_PER_SEC) 72 else 73 raise ArgumentError, "Unable to create a #{impl_class.name} from a #{arg.class.name}" unless arg.nil? || arg == :default 74 nil 75 end 76 end
# File lib/puppet/pops/types/p_timespan_type.rb 50 def eql?(o) 51 self.class == o.class && @from == o.numeric_from && @to == o.numeric_to 52 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 24 def from 25 @from == -Float::INFINITY ? nil : @from 26 end
# File lib/puppet/pops/types/p_timespan_type.rb 46 def hash 47 @from.hash ^ @to.hash 48 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 18 def intersect?(o) 19 self.class == o.class && !(@to < o.numeric_from || o.numeric_to < @from) 20 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 84 def merge(o) 85 if intersect?(o) || adjacent?(o) 86 new_min = numeric_from <= o.numeric_from ? numeric_from : o.numeric_from 87 new_max = numeric_to >= o.numeric_to ? numeric_to : o.numeric_to 88 self.class.new(new_min, new_max) 89 else 90 nil 91 end 92 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 36 def numeric_from 37 @from 38 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 42 def numeric_to 43 @to 44 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 30 def to 31 @to == Float::INFINITY ? nil : @to 32 end
# File lib/puppet/pops/types/p_timespan_type.rb 54 def unbounded? 55 @from == -Float::INFINITY && @to == Float::INFINITY 56 end