summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-29 17:27:50 +0100
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-29 17:27:50 +0100
commitb30ed04390647832002506039457fb93158d3cb8 (patch)
treeec02fb1edb8be59c8ac8c973cd99e0d4842a2145
parentf35fb819988408ad9a2e274bcdd268f7df177f52 (diff)
downloadpuppet-stdlib-b30ed04390647832002506039457fb93158d3cb8.tar.gz
puppet-stdlib-b30ed04390647832002506039457fb93158d3cb8.tar.bz2
First version. Simple capitalize function to use within Puppet DSL.
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
-rw-r--r--capitalize.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/capitalize.rb b/capitalize.rb
new file mode 100644
index 0000000..74d4f28
--- /dev/null
+++ b/capitalize.rb
@@ -0,0 +1,31 @@
+#
+# capitalize.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:capitalize, :type => :rvalue, :doc => <<-EOS
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "capitalize(): 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, 'capitalize(): Requires either an ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ result = value.collect { |i| i.is_a?(String) ? i.capitalize : i }
+ else
+ result = value.capitalize
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :