At the November 15 hackfest I show some watir
(http://wtr.rubyforge.org/) code I'd worked up and noted an issue with
a couple of the loops. Starting with something like this:
table = @@ta.cla_table
isFirst = true
table.each { |row|
if (isFirst) # skip the header row
isFirst = false
else
cla = CLA.new(row)
if (cla.amountIsInvalid)
@title = "Suspect CLA: #{cla.corrected_liability}
#{cla.total_offsets} #{cla.balance}"
suspectCLACount = suspectCLACount + 1
end
end
}
In which I skip the header row of the table with the isFirst flag, we
thought that shifting off the first element of table would simplify
things greatly, and that would be true, IF table were a simple array.
However, table is an instance of Watir::Table, which implements
Enumerable but is NOT an array, and doesn't have a shift method.
There's a way out, though. Watir::Table has a to_a method which
returns the table as a 2 dimensional array. (Though it warns that if
the table cells contain other tables or tricky HTML, it won't behave
well).
So the code above can be simplified to:
tarray = @@ta.cla_table.to_a
header = tarray.shift
tarray.each { |row|
cla = CLA.new(row)
if (cla.amountIsInvalid)
@title = "Suspect CLA: #{cla.corrected_liability}
#{cla.total_offsets} #{cla.balance}"
suspectCLACount = suspectCLACount + 1
end
}
With some minor changes to the CLA object, because arrays in Ruby are
0-based while Watir:Table is 1-based. Ergh.
Thanks for everyone's feedback. I hope to see you again.
--
It's actually a pretty big world,
it's just folded over on itself a lot.
_______________________________________________
PDXRuby mailing list
[email protected]
IRC: #pdx.rb on irc.freenode.net
http://lists.pdxruby.org/mailman/listinfo/pdxruby