5 # TODO(Krzysztof Wilczynski): We probably need to approach numeric values differently ...
7 module Puppet::Parser::Functions
8 newfunction(:range, :type => :rvalue, :doc => <<-EOS
9 When given range in the form of (start, stop) it will extrapolate a range as
16 Will return: [0,1,2,3,4,5,6,7,8,9]
20 Will return: ["a","b","c"]
24 # We support more than one argument but at least one is mandatory ...
25 raise(Puppet::ParseError, "range(): Wrong number of " +
26 "arguments given (#{arguments.size} for 1)") if arguments.size < 1
32 type = '..' # We select simplest type for Range available in Ruby ...
34 elsif arguments.size > 0
37 if m = value.match(/^(\w+)(\.\.\.?|\-)(\w+)$/)
43 elsif value.match(/^.+$/)
44 raise(Puppet::ParseError, 'range(): Unable to compute range ' +
45 'from the value given')
47 raise(Puppet::ParseError, 'range(): Unknown format of range given')
51 # Check whether we have integer value if so then make it so ...
52 if start.match(/^\d+$/)
61 when /^(\.\.|\-)$/ then (start .. stop)
62 when /^(\.\.\.)$/ then (start ... stop) # Exclusive of last element ...
65 result = range.collect { |i| i } # Get them all ... Pokemon ...
71 # vim: set ts=2 sw=2 et :