summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-24 01:35:49 +0100
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-24 01:35:49 +0100
commiteefd7a9fc4951b523419b207ea197a481878745d (patch)
tree78b11730a8f20e435e451ab84f28b481bcaae979
parentfa68d78b200befb286b3e18415dd7f820369f5e5 (diff)
Adding ability to specifiy range as the index when selecting indices to collect.
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
-rw-r--r--collect_indices.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/collect_indices.rb b/collect_indices.rb
index e96c3e9..cd087b9 100644
--- a/collect_indices.rb
+++ b/collect_indices.rb
@@ -22,8 +22,28 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, 'You must provide indices to collect')
end
- # In Puppet numbers are often string-encoded ...
- array = indices.collect { |i| array[i.to_i] }.compact
+ indices_list = []
+
+ indices.each do |i|
+ if m = i.match(/^(\d+)\-(\d+)$/)
+ start = m[1].to_i
+ stop = m[2].to_i
+
+ raise(Puppet::ParseError, 'Stop index in given indices range ' +
+ 'is smaller than the start index') if start > stop
+
+ (start .. stop).each { |i| indices_list << i.to_i }
+ else
+ if not i.match(/^\w+$/)
+ raise(Puppet::ParseError, 'Unknown format of given index')
+ end
+
+ # In Puppet numbers are often string-encoded ...
+ indices_list << i.to_i
+ end
+ end
+
+ array = indices_list.collect { |i| array[i] }.compact
return array
end