From 4da6d8222eeca060ad91c9a49f965ec1150a37c2 Mon Sep 17 00:00:00 2001 From: Krzysztof Wilczynski Date: Sat, 30 Apr 2011 02:54:47 +0100 Subject: Changed wording of the note in the comment. Signed-off-by: Krzysztof Wilczynski --- abs.rb | 2 +- capitalize.rb | 2 +- chomp.rb | 2 +- chop.rb | 2 +- downcase.rb | 32 ++++++++++++++++++++++++++++++++ lstrip.rb | 1 + upcase.rb | 32 ++++++++++++++++++++++++++++++++ 7 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 downcase.rb create mode 100644 upcase.rb diff --git a/abs.rb b/abs.rb index c3e90d4..0a554e4 100644 --- a/abs.rb +++ b/abs.rb @@ -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 diff --git a/chomp.rb b/chomp.rb index aba9e8d..e1d788a 100644 --- a/chomp.rb +++ b/chomp.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.chomp : i } else result = value.chomp diff --git a/chop.rb b/chop.rb index 32ce040..0f9af86 100644 --- a/chop.rb +++ b/chop.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.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 : diff --git a/lstrip.rb b/lstrip.rb index 241b683..a7b2656 100644 --- a/lstrip.rb +++ b/lstrip.rb @@ -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 : -- cgit v1.2.3