]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/grep.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / grep.rb
1 #
2 # grep.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:grep, :type => :rvalue, :doc => <<-EOS
7 This function searches through an array and returns any elements that match
8 the provided regular expression.
9
10 *Examples:*
11
12     grep(['aaa','bbb','ccc','aaaddd'], 'aaa')
13
14 Would return:
15
16     ['aaa','aaaddd']
17     EOS
18   ) do |arguments|
19
20     if (arguments.size != 2) then
21       raise(Puppet::ParseError, "grep(): Wrong number of arguments "+
22         "given #{arguments.size} for 2")
23     end
24
25     a = arguments[0]
26     pattern = Regexp.new(arguments[1])
27
28     a.grep(pattern)
29
30   end
31 end
32
33 # vim: set ts=2 sw=2 et :