diff options
author | Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> | 2011-04-29 18:09:57 +0100 |
---|---|---|
committer | Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> | 2011-04-29 18:09:57 +0100 |
commit | 020a2a23eedcfb4957ac55214d597ec911e9b454 (patch) | |
tree | 645f24094637644c8858c86b7622d0c9d20067f3 | |
parent | a038f6a04111382f07d63ceb4f4624eec3dd7034 (diff) | |
download | puppet-stdlib-020a2a23eedcfb4957ac55214d597ec911e9b454.tar.gz puppet-stdlib-020a2a23eedcfb4957ac55214d597ec911e9b454.tar.bz2 |
First version. Simple chop function to use within Puppet DSL.
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
-rw-r--r-- | chop.rb | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -0,0 +1,31 @@ +# +# chop.rb +# + +module Puppet::Parser::Functions + newfunction(:chop, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "chop(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + if not [Array, String].include?(klass) + raise(Puppet::ParseError, 'chop(): Requires either an ' + + 'array or string to work with') + end + + if value.is_a?(Array) + result = value.collect { |i| i.is_a?(String) ? i.chop : i } + else + result = value.chop + end + + return result + end +end + +# vim: set ts=2 sw=2 et : |