views:

45

answers:

1

Currnetly I am doing

words = []
words << "philip morris"
words << "Philip morris"
words << "philip Morris"
words << "Philip Morris"
for word in words
  doc.search("[text()*='#{word}']")
end

When I was using hpricot I found where to downcase the results within the gem so I could just keep all my searchs lowercase, however nokogiri has been quite difficult to find where one could even do that. Is anyone aware of a way to do this? Thank you very much for your time

+1  A: 

The lower-case XPath function is not available but you can use the translate XPath 1.0 function to convert your text to lowercase e.g. for the English alphabet:

translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')

I couldn't seem to use this in combination with the *= operator but you can use contains to do a substring search instead, making the full thing:

doc.search("//*[contains(translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'philip morris')]")
mikej
Thank you so much :) That works perfectly!
Davinj