Update stdlib
[mirror/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 given #{arguments.size} for 2")
22     end
23
24     a = arguments[0]
25     pattern = Regexp.new(arguments[1])
26
27     a.grep(pattern)
28
29   end
30 end
31
32 # vim: set ts=2 sw=2 et :