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