class Puppet::Pops::Types::PTimespanType
Constants
- DEFAULT
Public Class Methods
new_function(type)
click to toggle source
# File lib/puppet/pops/types/p_timespan_type.rb 107 def self.new_function(type) 108 @new_function ||= Puppet::Functions.create_loaded_function(:new_timespan, type.loader) do 109 local_types do 110 type 'Formats = Variant[String[2],Array[String[2], 1]]' 111 end 112 113 dispatch :from_seconds do 114 param 'Variant[Integer,Float]', :seconds 115 end 116 117 dispatch :from_string do 118 param 'String[1]', :string 119 optional_param 'Formats', :format 120 end 121 122 dispatch :from_fields do 123 param 'Integer', :days 124 param 'Integer', :hours 125 param 'Integer', :minutes 126 param 'Integer', :seconds 127 optional_param 'Integer', :milliseconds 128 optional_param 'Integer', :microseconds 129 optional_param 'Integer', :nanoseconds 130 end 131 132 dispatch :from_string_hash do 133 param <<-TYPE, :hash_arg 134 Struct[{ 135 string => String[1], 136 Optional[format] => Formats 137 }] 138 TYPE 139 end 140 141 dispatch :from_fields_hash do 142 param <<-TYPE, :hash_arg 143 Struct[{ 144 Optional[negative] => Boolean, 145 Optional[days] => Integer, 146 Optional[hours] => Integer, 147 Optional[minutes] => Integer, 148 Optional[seconds] => Integer, 149 Optional[milliseconds] => Integer, 150 Optional[microseconds] => Integer, 151 Optional[nanoseconds] => Integer 152 }] 153 TYPE 154 end 155 156 def from_seconds(seconds) 157 Time::Timespan.new((seconds * Time::NSECS_PER_SEC).to_i) 158 end 159 160 def from_string(string, format = Time::Timespan::Format::DEFAULTS) 161 Time::Timespan.parse(string, format) 162 end 163 164 def from_fields(days, hours, minutes, seconds, milliseconds = 0, microseconds = 0, nanoseconds = 0) 165 Time::Timespan.from_fields(false, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) 166 end 167 168 def from_string_hash(args_hash) 169 Time::Timespan.from_string_hash(args_hash) 170 end 171 172 def from_fields_hash(args_hash) 173 Time::Timespan.from_fields_hash(args_hash) 174 end 175 end 176 end
register_ptype(loader, ir)
click to toggle source
# File lib/puppet/pops/types/p_timespan_type.rb 100 def self.register_ptype(loader, ir) 101 create_ptype(loader, ir, 'ScalarType', 102 'from' => { KEY_TYPE => POptionalType.new(PTimespanType::DEFAULT), KEY_VALUE => nil }, 103 'to' => { KEY_TYPE => POptionalType.new(PTimespanType::DEFAULT), KEY_VALUE => nil } 104 ) 105 end
Public Instance Methods
from_fields(days, hours, minutes, seconds, milliseconds = 0, microseconds = 0, nanoseconds = 0)
click to toggle source
# File lib/puppet/pops/types/p_timespan_type.rb 164 def from_fields(days, hours, minutes, seconds, milliseconds = 0, microseconds = 0, nanoseconds = 0) 165 Time::Timespan.from_fields(false, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) 166 end
from_fields_hash(args_hash)
click to toggle source
# File lib/puppet/pops/types/p_timespan_type.rb 172 def from_fields_hash(args_hash) 173 Time::Timespan.from_fields_hash(args_hash) 174 end
from_seconds(seconds)
click to toggle source
# File lib/puppet/pops/types/p_timespan_type.rb 156 def from_seconds(seconds) 157 Time::Timespan.new((seconds * Time::NSECS_PER_SEC).to_i) 158 end
from_string(string, format = Time::Timespan::Format::DEFAULTS)
click to toggle source
# File lib/puppet/pops/types/p_timespan_type.rb 160 def from_string(string, format = Time::Timespan::Format::DEFAULTS) 161 Time::Timespan.parse(string, format) 162 end
from_string_hash(args_hash)
click to toggle source
# File lib/puppet/pops/types/p_timespan_type.rb 168 def from_string_hash(args_hash) 169 Time::Timespan.from_string_hash(args_hash) 170 end
generalize()
click to toggle source
# File lib/puppet/pops/types/p_timespan_type.rb 178 def generalize 179 DEFAULT 180 end
impl_class()
click to toggle source
# File lib/puppet/pops/types/p_timespan_type.rb 182 def impl_class 183 Time::Timespan 184 end
instance?(o, guard = nil)
click to toggle source
# File lib/puppet/pops/types/p_timespan_type.rb 186 def instance?(o, guard = nil) 187 o.is_a?(Time::Timespan) && o >= @from && o <= @to 188 end