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
Overview
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, #instance?, #intersect?, #merge, #numeric_from, #numeric_to, #to, #unbounded?
Methods inherited from PScalarType
#instance?, #roundtrip_with_string?
Methods inherited from PAnyType
#==, #accept, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, #create, create, #eql?, #hash, #instance?, #iterable?, #iterable_type, #kind_of_callable?, #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
Constructor Details
This class inherits a constructor from Puppet::Pops::Types::PAbstractTimeDataType
Class Method Details
.new_function(_, loader) ⇒ Object
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 178 179 |
# File 'lib/puppet/pops/types/p_timespan_type.rb', line 110 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 " Struct[{\n string => String[1],\n Optional[format] => Formats\n }]\n TYPE\n end\n\n dispatch :from_fields_hash do\n param <<-TYPE, :hash_arg\n Struct[{\n Optional[negative] => Boolean,\n Optional[days] => Integer,\n Optional[hours] => Integer,\n Optional[minutes] => Integer,\n Optional[seconds] => Integer,\n Optional[milliseconds] => Integer,\n Optional[microseconds] => Integer,\n Optional[nanoseconds] => Integer\n }]\n TYPE\n end\n\n def from_seconds(seconds)\n Time::Timespan.new((seconds * Time::NSECS_PER_SEC).to_i)\n end\n\n def from_string(string, format = Time::Timespan::Format::DEFAULTS)\n Time::Timespan.parse(string, format)\n end\n\n def from_fields(days, hours, minutes, seconds, milliseconds = 0, microseconds = 0, nanoseconds = 0)\n Time::Timespan.from_fields(days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds)\n end\n\n def from_string_hash(args_hash)\n Time::Timespan.from_string_hash(args_hash)\n end\n\n def from_fields_hash(args_hash)\n Time::Timespan.from_fields_hash(args_hash)\n end\n end\nend\n", :hash_arg |
.register_ptype(loader, ir) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/puppet/pops/types/p_timespan_type.rb', line 103 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 |