PDA

View Full Version : searching a string for keywords - failing in shell


jrwizzard
May 29th, 2008, 03:53 PM
Hi everyone, I am new to ruby, and I am in a crash course to learn it.

The goal here is to search the "externalhash" array, which are URLs, for "badwords" which is an array of keywords. The current output for the URL is to the screen, for testing purposes.. In IRB the logic worked, using single strings for key and word. When I pump it through the array, and output the contents of key and word each pass, I see valid strings. But when I plug in the logic:

unless key.to_s.upcase.scan(word.to-s.upcase).to_s.length.eql?(0)
puts key
end

into windows command shell, it returns only what matches exactly, it doesn't match on bits and pieces. For example; if the key is www.football.com, and the word is ball, it would work in IRB, but in windows command shell it doesn't. In windows command shell it only works if I add 'www.football.com' as a word. So I am clueless why it works in IRB but not command shell, any assistance is greatly appreciated.





name = "external_"+"#{ARGV[0]}"+".txt"
output = File.new("#{name}", "w")
externalHash.each_key do |key|
output.puts key
badwords.each do |word|
unless key.to_s.upcase.scan(word.to-s.upcase).to_s.length.eql?(0)
puts key
end
end
end

jrwizzard
May 29th, 2008, 05:16 PM
I figured it out, i needed to chomp my keyword list...