Mercurial > repos > other > Puppet
comparison modules/stdlib/lib/puppet/parser/functions/squeeze.rb @ 272:c42fb28cff86
Update to a newer Python module
This also pulls in an EPEL module (which we don't use) and a newer
stdlib version.
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 03 Jan 2020 19:56:04 +0000 |
parents | 956e484adc12 |
children | d9352a684e62 |
comparison
equal
deleted
inserted
replaced
271:c62728474654 | 272:c42fb28cff86 |
---|---|
1 # | 1 # |
2 # squeeze.rb | 2 # squeeze.rb |
3 # | 3 # |
4 module Puppet::Parser::Functions | |
5 newfunction(:squeeze, :type => :rvalue, :doc => <<-DOC | |
6 Returns a new string where runs of the same character that occur in this set are replaced by a single character. | |
7 DOC | |
8 ) do |arguments| | |
4 | 9 |
5 module Puppet::Parser::Functions | 10 if (arguments.size != 2) && (arguments.size != 1) |
6 newfunction(:squeeze, :type => :rvalue, :doc => <<-EOS | 11 raise(Puppet::ParseError, "squeeze(): Wrong number of arguments given #{arguments.size} for 2 or 1") |
7 Returns a new string where runs of the same character that occur in this set are replaced by a single character. | |
8 EOS | |
9 ) do |arguments| | |
10 | |
11 if ((arguments.size != 2) and (arguments.size != 1)) then | |
12 raise(Puppet::ParseError, "squeeze(): Wrong number of arguments "+ | |
13 "given #{arguments.size} for 2 or 1") | |
14 end | 12 end |
15 | 13 |
16 item = arguments[0] | 14 item = arguments[0] |
17 squeezeval = arguments[1] | 15 squeezeval = arguments[1] |
18 | 16 |
19 if item.is_a?(Array) then | 17 if item.is_a?(Array) |
20 if squeezeval then | 18 if squeezeval |
21 item.collect { |i| i.squeeze(squeezeval) } | 19 item.map { |i| i.squeeze(squeezeval) } |
22 else | 20 else |
23 item.collect { |i| i.squeeze } | 21 item.map { |i| i.squeeze } |
24 end | 22 end |
23 elsif squeezeval | |
24 item.squeeze(squeezeval) | |
25 else | 25 else |
26 if squeezeval then | 26 item.squeeze |
27 item.squeeze(squeezeval) | |
28 else | |
29 item.squeeze | |
30 end | |
31 end | 27 end |
32 | |
33 end | 28 end |
34 end | 29 end |
35 | 30 |
36 # vim: set ts=2 sw=2 et : | 31 # vim: set ts=2 sw=2 et : |