I'm writing a program to parse a basic text file, and compare certain lines from it to results from a test. I'm using specific words to find the line which should be compared to the result from the test, and then passing or failing the result based upon whether or not the line matches the result (they should be exactly the same). I'm using the following general format:
File.open(file).each do |line|
if line include? "Revision"
if line==result
puts "Correct"
else
puts "Fail"
Most of the cases are just one line, so that's easy enough. But for a few of the cases, my result is 4 lines long, not just one. So, once I find the line I need, I need to check to see if the result is equal to the line of interest plus the following 3 lines after it. This is how the information is formatted in the file being read, and also how the result from the test should look:
Product Serial Number: 12058-2865
Product Part Number: 3456
Product Type: H-Type
Product Version: 2.07
Once the line of interest is found, I just need to compare the line of interest plus the next three lines to the whole result.
if line include? "Product Serial Number"
#if (#this line and the next 3) == result
puts Correct
else
puts "Fail"
How do I do this?