From aafce9c99b779855e1e10e5a337848fa9f676a01 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Sat, 30 Apr 2011 16:00:49 +0200 Subject: Moved more functions into lib/puppet/parser/functions/ --- lib/puppet/parser/functions/strip.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/puppet/parser/functions/strip.rb (limited to 'lib/puppet/parser/functions/strip.rb') diff --git a/lib/puppet/parser/functions/strip.rb b/lib/puppet/parser/functions/strip.rb new file mode 100644 index 0000000..ebab20e --- /dev/null +++ b/lib/puppet/parser/functions/strip.rb @@ -0,0 +1,31 @@ +# +# strip.rb +# + +module Puppet::Parser::Functions + newfunction(:strip, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "strip(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'strip(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + result = value.collect { |i| i.is_a?(String) ? i.strip : i } + else + result = value.strip + end + + return result + end +end + +# vim: set ts=2 sw=2 et : -- cgit v1.2.3 From 19313b43ea04066a88a0b78e83650ac52785e2e9 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 22:18:56 +0100 Subject: (#3) Apply missing documentation to more functions. --- lib/puppet/parser/functions/strip.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/puppet/parser/functions/strip.rb') diff --git a/lib/puppet/parser/functions/strip.rb b/lib/puppet/parser/functions/strip.rb index ebab20e..5f4630d 100644 --- a/lib/puppet/parser/functions/strip.rb +++ b/lib/puppet/parser/functions/strip.rb @@ -4,6 +4,14 @@ module Puppet::Parser::Functions newfunction(:strip, :type => :rvalue, :doc => <<-EOS +This function removes leading and trailing whitespace from a string or from +every string inside an array. + +*Examples:* + + strip(" aaa ") + +Would result in: "aaa" EOS ) do |arguments| -- cgit v1.2.3