lib/masticate/exclude.rb in masticate-0.2.3 vs lib/masticate/exclude.rb in masticate-0.3
- old
+ new
@@ -17,10 +17,22 @@
end
def crunch(row)
if !@headers
@headers = row
- @index = @headers.index(@field) or raise "Unable to find column '#{@field}' in headers"
+ f = @field
+ @index =
+ case f
+ when Fixnum, /^\d+$/
+ f = f.to_i
+ if f > row.count
+ raise "Cannot pluck column #{f}, there are only #{row.count} fields"
+ else
+ f-1
+ end
+ else
+ row.index(f) or raise "Unable to find column '#{f}' in headers"
+ end
row
elsif row
if row[@index] == @value
# exclude
else