diff options
author | Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> | 2011-04-30 02:54:47 +0100 |
---|---|---|
committer | Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> | 2011-04-30 02:54:47 +0100 |
commit | 4da6d8222eeca060ad91c9a49f965ec1150a37c2 (patch) | |
tree | cd1d49007085dfaebe9d52b9bd5c7be03723b8da | |
parent | db7a27cf5b0cb5667b17e2cbc686bff4be3966b7 (diff) | |
download | puppet-stdlib-4da6d8222eeca060ad91c9a49f965ec1150a37c2.tar.gz puppet-stdlib-4da6d8222eeca060ad91c9a49f965ec1150a37c2.tar.bz2 |
Changed wording of the note in the comment.
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
-rw-r--r-- | abs.rb | 2 | ||||
-rw-r--r-- | capitalize.rb | 2 | ||||
-rw-r--r-- | chomp.rb | 2 | ||||
-rw-r--r-- | chop.rb | 2 | ||||
-rw-r--r-- | downcase.rb | 32 | ||||
-rw-r--r-- | lstrip.rb | 1 | ||||
-rw-r--r-- | upcase.rb | 32 |
7 files changed, 69 insertions, 4 deletions
@@ -12,7 +12,7 @@ module Puppet::Parser::Functions value = arguments[0] - # Numbers in Puppet are often string-encoded ... + # Numbers in Puppet are often string-encoded which is troublesome ... if value.is_a?(String) if value.match(/^-?(?:\d+)(?:\.\d+){1}$/) value = value.to_f diff --git a/capitalize.rb b/capitalize.rb index ac6cc50..f902cb3 100644 --- a/capitalize.rb +++ b/capitalize.rb @@ -19,7 +19,7 @@ module Puppet::Parser::Functions end if value.is_a?(Array) - # Numbers in Puppet are often string-encoded ... + # Numbers in Puppet are often string-encoded which is troublesome ... result = value.collect { |i| i.is_a?(String) ? i.capitalize : i } else result = value.capitalize @@ -19,7 +19,7 @@ module Puppet::Parser::Functions end if value.is_a?(Array) - # Numbers in Puppet are often string-encoded ... + # Numbers in Puppet are often string-encoded which is troublesome ... result = value.collect { |i| i.is_a?(String) ? i.chomp : i } else result = value.chomp @@ -19,7 +19,7 @@ module Puppet::Parser::Functions end if value.is_a?(Array) - # Numbers in Puppet are often string-encoded ... + # Numbers in Puppet are often string-encoded which is troublesome ... result = value.collect { |i| i.is_a?(String) ? i.chop : i } else result = value.chop diff --git a/downcase.rb b/downcase.rb new file mode 100644 index 0000000..71f8480 --- /dev/null +++ b/downcase.rb @@ -0,0 +1,32 @@ +# +# downcase.rb +# + +module Puppet::Parser::Functions + newfunction(:downcase, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "downcase(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'downcase(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.downcase : i } + else + result = value.downcase + end + + return result + end +end + +# vim: set ts=2 sw=2 et : @@ -19,6 +19,7 @@ module Puppet::Parser::Functions end if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... result = value.collect { |i| i.is_a?(String) ? i.lstrip : i } else result = value.lstrip diff --git a/upcase.rb b/upcase.rb new file mode 100644 index 0000000..8a9769d --- /dev/null +++ b/upcase.rb @@ -0,0 +1,32 @@ +# +# upcase.rb +# + +module Puppet::Parser::Functions + newfunction(:upcase, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "upcase(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'upcase(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.upcase : i } + else + result = value.upcase + end + + return result + end +end + +# vim: set ts=2 sw=2 et : |