Class: Puppet::Pops::Types::PAbstractTimeDataType

Inherits:
PAbstractRangeType show all
Defined in:
lib/puppet/pops/types/p_timespan_type.rb

Direct Known Subclasses

PTimespanType, PTimestampType

Constant Summary

Constants inherited from PScalarType

Puppet::Pops::Types::PScalarType::DEFAULT

Constants inherited from PAnyType

Puppet::Pops::Types::PAnyType::DEFAULT

Instance Method Summary collapse

Methods inherited from PAbstractRangeType

#eql?, #from, #hash, #instance?, #intersect?, #numeric_from, #numeric_to, #to, #unbounded?

Methods inherited from PScalarType

#instance?, register_ptype

Methods inherited from PAnyType

#==, #accept, #assignable?, #callable?, #callable_args?, #check_self_recursion, #eql?, #generalize, #hash, #instance?, #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

#accept

Methods included from PuppetObject

#_ptype

Constructor Details

#initialize(min = nil, max = nil) ⇒ PAbstractTimeDataType

Returns a new instance of PAbstractTimeDataType.

Parameters:

  • min (AbstractTime) (defaults to: nil)

    lower bound for this type. Nil or :default means unbounded

  • max (AbstractTime) (defaults to: nil)

    upper bound for this type. Nil or :default means unbounded



6
7
8
# File 'lib/puppet/pops/types/p_timespan_type.rb', line 6

def initialize(min = nil, max = nil)
  super(convert_arg(min, true), convert_arg(max, false))
end

Instance Method Details

#_assignable?(o, guard) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/puppet/pops/types/p_timespan_type.rb', line 46

def _assignable?(o, guard)
  self.class == o.class && numeric_from <= o.numeric_from && numeric_to >= o.numeric_to
end

#convert_arg(arg, min) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet/pops/types/p_timespan_type.rb', line 10

def convert_arg(arg, min)
  case arg
  when impl_class
    arg
  when Hash
    impl_class.from_hash(arg)
  when nil, :default
    nil
  when String
    impl_class.parse(arg)
  when Integer
    arg == impl_class.new(arg * Time::NSECS_PER_SEC)
  when Float
    arg == (min ? -Float::INFINITY : Float::INFINITY) ? arg : impl_class.new(arg * Time::NSECS_PER_SEC)
  else
    raise ArgumentError, "Unable to create a #{impl_class.name} from a #{arg.class.name}" unless arg.nil? || arg == :default
    nil
  end
end

#merge(o) ⇒ PAbstractTimeDataType?

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`

Parameters:

Returns:



36
37
38
39
40
41
42
43
44
# File 'lib/puppet/pops/types/p_timespan_type.rb', line 36

def merge(o)
  if intersect?(o) || adjacent?(o)
    new_min = numeric_from <= o.numeric_from ? numeric_from : o.numeric_from
    new_max = numeric_to >= o.numeric_to ? numeric_to : o.numeric_to
    self.class.new(new_min, new_max)
  else
    nil
  end
end