puppetlabs-stdlib/lib/puppet/parser/functions/sort.rb

28 lines
511 B
Ruby
Raw Normal View History

#
# sort.rb
#
module Puppet::Parser::Functions
newfunction(:sort, :type => :rvalue, :doc => <<-EOS
Sorts strings and arrays lexically.
EOS
) do |arguments|
2011-07-24 01:39:17 +02:00
if (arguments.size != 1) then
raise(Puppet::ParseError, "sort(): Wrong number of arguments "+
2011-07-24 01:39:17 +02:00
"given #{arguments.size} for 1")
end
2011-07-29 01:10:31 +02:00
value = arguments[0]
if value.is_a?(Array) then
value.sort
elsif value.is_a?(String) then
2011-07-30 01:44:02 +02:00
value.split("").sort.join("")
2011-07-29 01:10:31 +02:00
end
2011-07-24 01:39:17 +02:00
end
end
# vim: set ts=2 sw=2 et :