source: other-projects/hathitrust/vagrant-solr-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/swapcase.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: 859 bytes
Line 
1#
2# swapcase.rb
3#
4
5module Puppet::Parser::Functions
6 newfunction(:swapcase, :type => :rvalue, :doc => <<-EOS
7This function will swap the existing case of a string.
8
9*Examples:*
10
11 swapcase("aBcD")
12
13Would result in: "AbCd"
14 EOS
15 ) do |arguments|
16
17 raise(Puppet::ParseError, "swapcase(): Wrong number of arguments " +
18 "given (#{arguments.size} for 1)") if arguments.size < 1
19
20 value = arguments[0]
21
22 unless value.is_a?(Array) || value.is_a?(String)
23 raise(Puppet::ParseError, 'swapcase(): Requires either ' +
24 'array or string to work with')
25 end
26
27 if value.is_a?(Array)
28 # Numbers in Puppet are often string-encoded which is troublesome ...
29 result = value.collect { |i| i.is_a?(String) ? i.swapcase : i }
30 else
31 result = value.swapcase
32 end
33
34 return result
35 end
36end
37
38# vim: set ts=2 sw=2 et :
Note: See TracBrowser for help on using the repository browser.