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?, #callable_with?, #check_self_recursion, #create, #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(from = nil, to = nil) ⇒ PAbstractTimeDataType

Returns a new instance of PAbstractTimeDataType.



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

def initialize(from = nil, to = nil)
  super(convert_arg(from, true), convert_arg(to, false))
end

Instance Method Details

#_assignable?(o, guard) ⇒ 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



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