source: other-projects/hathitrust/vagrant-solr-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/upcase.rb@ 30960

Last change on this file since 30960 was 30960, checked in by davidb, 7 years ago

Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster

File size: 1.1 KB
Line 
1#
2# upcase.rb
3#
4
5module Puppet::Parser::Functions
6 newfunction(:upcase, :type => :rvalue, :doc => <<-EOS
7Converts a string or an array of strings to uppercase.
8
9*Examples:*
10
11 upcase("abcd")
12
13Will return:
14
15 ABCD
16 EOS
17 ) do |arguments|
18
19 raise(Puppet::ParseError, "upcase(): Wrong number of arguments " +
20 "given (#{arguments.size} for 1)") if arguments.size != 1
21
22 value = arguments[0]
23
24 unless value.is_a?(Array) || value.is_a?(Hash) || value.respond_to?(:upcase)
25 raise(Puppet::ParseError, 'upcase(): Requires an ' +
26 'array, hash or object that responds to upcase in order to work')
27 end
28
29 if value.is_a?(Array)
30 # Numbers in Puppet are often string-encoded which is troublesome ...
31 result = value.collect { |i| function_upcase([i]) }
32 elsif value.is_a?(Hash)
33 result = {}
34 value.each_pair do |k, v|
35 result[function_upcase([k])] = function_upcase([v])
36 end
37 else
38 result = value.upcase
39 end
40
41 return result
42 end
43end
44
45# vim: set ts=2 sw=2 et :
Note: See TracBrowser for help on using the repository browser.