Ow, this worked! How I managed to spend two hours fiddling with the code 
and not end up trying that I don't know.

Thanks for your help.

Typical of Ruby, its easier than you thought.