raise(Puppet::ParseError, 'values_at(): Requires array to work with')
end
raise(Puppet::ParseError, 'values_at(): Requires array to work with')
end
- indices = [arguments.shift].flatten() # Get them all ... Pokemon ...
+ indices = [arguments.shift].flatten # Get them all ... Pokemon ...
- if not indices or indices.empty?
+ if !indices || indices.empty?
raise(Puppet::ParseError, 'values_at(): You must provide at least one positive index to collect')
end
raise(Puppet::ParseError, 'values_at(): You must provide at least one positive index to collect')
end
- result = []
indices_list = []
indices.each do |i|
i = i.to_s
indices_list = []
indices.each do |i|
i = i.to_s
- if m = i.match(/^(\d+)(\.\.\.?|\-)(\d+)$/)
+ m = i.match(%r{^(\d+)(\.\.\.?|\-)(\d+)$})
+ if m
start = m[1].to_i
stop = m[3].to_i
type = m[2]
start = m[1].to_i
stop = m[3].to_i
type = m[2]
- if start > stop
- raise(Puppet::ParseError, 'values_at(): Stop index in given indices range is smaller than the start index')
- elsif stop > array.size - 1 # First element is at index 0 is it not?
- raise(Puppet::ParseError, 'values_at(): Stop index in given indices range exceeds array size')
- end
+ raise(Puppet::ParseError, 'values_at(): Stop index in given indices range is smaller than the start index') if start > stop
+ raise(Puppet::ParseError, 'values_at(): Stop index in given indices range exceeds array size') if stop > array.size - 1 # First element is at index 0 is it not?
range = case type
range = case type
- when /^(\.\.|\-)$/ then (start .. stop)
- when /^(\.\.\.)$/ then (start ... stop) # Exclusive of last element ...
- end
+ when %r{^(\.\.|\-)$} then (start..stop)
+ when %r{^(\.\.\.)$} then (start...stop) # Exclusive of last element ...
+ end
- range.each { |i| indices_list << i.to_i }
+ range.each { |i| indices_list << i.to_i } # rubocop:disable Lint/ShadowingOuterLocalVariable : Value is meant to be shadowed
else
# Only positive numbers allowed in this case ...
else
# Only positive numbers allowed in this case ...
- if not i.match(/^\d+$/)
+ unless i =~ %r{^\d+$}
raise(Puppet::ParseError, 'values_at(): Unknown format of given index')
end
raise(Puppet::ParseError, 'values_at(): Unknown format of given index')