Class: Puppet::Pops::Types::PTimespanType
- Inherits:
-
PAbstractTimeDataType
- Object
- TypedModelObject
- PAnyType
- PScalarType
- PAbstractTimeDataType
- Puppet::Pops::Types::PTimespanType
- 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, #eql?, #from, #hash, #initialize, #intersect?, #merge, #numeric_from, #numeric_to, #to, #unbounded?
Methods inherited from PScalarType
Methods inherited from PAnyType
#==, #accept, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, create, #create, #eql?, #hash, #iterable?, #iterable_type, #kind_of_callable?, #loader, #name, #new_function, #normalize, #really_instance?, #resolve, #roundtrip_with_string?, simple_name, #simple_name, #to_alias_expanded_s, #to_s
Methods inherited from TypedModelObject
_pcore_type, create_ptype, register_ptypes
Methods included from Visitable
Methods included from PuppetObject
#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type, #to_s
Constructor Details
This class inherits a constructor from Puppet::Pops::Types::PAbstractTimeDataType
Class Method Details
.new_function(type) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/puppet/pops/types/p_timespan_type.rb', line 108 def self.new_function(type) @new_function ||= Puppet::Functions.create_loaded_function(:new_timespan, type.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(false, 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
102 103 104 105 106 |
# File 'lib/puppet/pops/types/p_timespan_type.rb', line 102 def self.register_ptype(loader, ir) create_ptype(loader, ir, 'ScalarType', 'from' => { KEY_TYPE => POptionalType.new(PTimespanType::DEFAULT), KEY_VALUE => nil }, 'to' => { KEY_TYPE => POptionalType.new(PTimespanType::DEFAULT), KEY_VALUE => nil }) end |