X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fbool2num.rb;h=bafe0bd436dcfa1ae6be69bff2b6ec7cab2bd179;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=92e4ddef3114c39307ab4fb0e4c69c96035d1bfd;hpb=6963202b4b62c2816655ac9532521b018fdf83bd;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/bool2num.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/bool2num.rb index 92e4ddef3..bafe0bd43 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/bool2num.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/bool2num.rb @@ -1,17 +1,35 @@ # # bool2num.rb # - module Puppet::Parser::Functions - newfunction(:bool2num, :type => :rvalue, :doc => <<-EOS - Converts a boolean to a number. Converts the values: + newfunction(:bool2num, :type => :rvalue, :doc => <<-DOC + @summary + Converts a boolean to a number. + + Converts the values: + ``` false, f, 0, n, and no to 0 true, t, 1, y, and yes to 1 + ``` Requires a single boolean or string as an input. - EOS - ) do |arguments| - raise(Puppet::ParseError, "bool2num(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1 + > *Note:* + since Puppet 5.0.0 it is possible to create new data types for almost any + datatype using the type system and the built-in + [`Numeric.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-numeric), + [`Integer.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-integer), and + [`Float.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-float) + function are used to convert to numeric values. + ``` + notice(Integer(false)) # Notices 0 + notice(Float(true)) # Notices 1.0 + ``` + + @return [Integer] The converted value as a number + DOC + ) do |arguments| + + raise(Puppet::ParseError, "bool2num(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = function_str2bool([arguments[0]])