Class: Puppet::Pops::Types::PTimespanType

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

Constant Summary collapse

DEFAULT =
PTimespanType.new(nil, nil)

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PAbstractTimeDataType

#_assignable?, #convert_arg, #initialize, #merge

Methods inherited from PAbstractRangeType

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

Methods inherited from PScalarType

#instance?

Methods inherited from PAnyType

#==, #accept, #assignable?, #callable?, #callable_args?, #check_self_recursion, #eql?, #hash, #instance?, #iterable?, #iterable_type, #kind_of_callable?, #name, #new_function, #normalize, #really_instance?, #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

This class inherits a constructor from Puppet::Pops::Types::PAbstractTimeDataType

Class Method Details

.new_function(_, loader) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/puppet/pops/types/p_timespan_type.rb', line 59

def self.new_function(_, loader)
  @new_function ||= Puppet::Functions.create_loaded_function(:new_timespan, loader) do
    local_types do
      type 'Formats = Variant[String[2],Array[String[2]], 1]'
    end

    dispatch :from_seconds do
      param           'Variant[Integer,Float]', :seconds
    end

    dispatch :from_string do
      param           'String[1]', :string
      optional_param  'Formats', :format
    end

    dispatch :from_fields do
      param          'Integer', :days
      param          'Integer', :hours
      param          'Integer', :minutes
      param          'Integer', :seconds
      optional_param 'Integer', :milliseconds
      optional_param 'Integer', :microseconds
      optional_param 'Integer', :nanoseconds
    end

    dispatch :from_string_hash do
      param <<-TYPE, :hash_arg
        Struct[{
          string => String[1],
          Optional[format] => Formats
        }]
      TYPE
    end

    dispatch :from_fields_hash do
      param <<-TYPE, :hash_arg
        Struct[{
          Optional[negative] => Boolean,
          Optional[days] => Integer,
          Optional[hours] => Integer,
          Optional[minutes] => Integer,
          Optional[seconds] => Integer,
          Optional[milliseconds] => Integer,
          Optional[microseconds] => Integer,
          Optional[nanoseconds] => Integer
        }]
      TYPE
    end

    def from_seconds(seconds)
      Time::Timespan.new((seconds * Time::NSECS_PER_SEC).to_i)
    end

    def from_string(string, format = Time::Timespan::Format::DEFAULTS)
      Time::Timespan.parse(string, format)
    end

    def from_fields(days, hours, minutes, seconds, milliseconds = 0, microseconds = 0, nanoseconds = 0)
      Time::Timespan.from_fields(days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds)
    end

    def from_string_hash(args_hash)
      Time::Timespan.from_string_hash(args_hash)
    end

    def from_fields_hash(args_hash)
      Time::Timespan.from_fields_hash(args_hash)
    end
  end
end

.register_ptype(loader, ir) ⇒ Object



52
53
54
55
56
57
# File 'lib/puppet/pops/types/p_timespan_type.rb', line 52

def self.register_ptype(loader, ir)
  create_ptype(loader, ir, 'ScalarType',
    'from' => { KEY_TYPE => PTimespanType::DEFAULT, KEY_VALUE => :default },
    'to' => { KEY_TYPE => PTimespanType::DEFAULT, KEY_VALUE => :default }
  )
end

Instance Method Details

#generalizeObject



130
131
132
# File 'lib/puppet/pops/types/p_timespan_type.rb', line 130

def generalize
  DEFAULT
end

#impl_classObject



134
135
136
# File 'lib/puppet/pops/types/p_timespan_type.rb', line 134

def impl_class
  Time::Timespan
end