Mercurial > repos > other > Puppet
comparison modules/stdlib/lib/puppet/parser/functions/swapcase.rb @ 0:956e484adc12
Initial public release of Puppet configs
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 16 Aug 2014 19:47:38 +0000 |
parents | |
children | addb0ea390a1 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:956e484adc12 |
---|---|
1 # | |
2 # swapcase.rb | |
3 # | |
4 | |
5 module Puppet::Parser::Functions | |
6 newfunction(:swapcase, :type => :rvalue, :doc => <<-EOS | |
7 This function will swap the existing case of a string. | |
8 | |
9 *Examples:* | |
10 | |
11 swapcase("aBcD") | |
12 | |
13 Would 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 klass = value.class | |
22 | |
23 unless [Array, String].include?(klass) | |
24 raise(Puppet::ParseError, 'swapcase(): Requires either ' + | |
25 'array or string to work with') | |
26 end | |
27 | |
28 if value.is_a?(Array) | |
29 # Numbers in Puppet are often string-encoded which is troublesome ... | |
30 result = value.collect { |i| i.is_a?(String) ? i.swapcase : i } | |
31 else | |
32 result = value.swapcase | |
33 end | |
34 | |
35 return result | |
36 end | |
37 end | |
38 | |
39 # vim: set ts=2 sw=2 et : |