Hi experts,
I started working with with Ruby and this looks like a rather simple problem I think, but still couldn't solve it.
products = Array.new
doc.search( "//td[@class='foo']" ).each do |foo|
products << foo.inner_html.split(',')
end
NB: search is a Hpricot (ruby gem) method that finds all <TD> where class='foo' in a previously loaded HTML document and returns its contents (inner_html).
Now this seems to yield an array of arrays (2D array).
e.g. if the HTML document contains
<td class='foo'>abc,def</td>
<td class='foo'>ghi,jkl</td>
<td class='foo'>mno,pqr</td>
<td class='foo'>stu,vwx</td>
then Array products would look like this:
[abc][def]
[ghi][jkl]
[mno][pqr]
[stu][vwx]
Now, what I want to do is use gsub with a regex on def, jkl, pqr, vwx.
Of course, this is just an example, and the actual array is much bigger.
How do I access those array fields? Maybe iterate over the array somehow?
Thanks for your help.
Start Free Trial