Mentioned in an earlier post, roo is a great gem to use with watir to do excel validations. You can use roo to find values in specific cells or within a range of cells. Naturally, you would want to do your data analysis across a range of cells to avoid unnecessary work and lines of code.

Let’s say you want to do some analysis on the value within an Excel and validate that the value is less than 1000. You can call that specific cell and write a comparison statement.
excel example
(Assuming you have defined your excel file using roo as Excelfile)

Although the code above works, it would be very tedious to apply the same logic to a file with thousands of cells that need to be analyzed. To solve this problem, you can use ruby’s each method to quickly iterate the same comparison statement over a range of values.

Ruby’s each statement allows you to define an array, and then iterate the same functions/operations for all values in that array.

In our excel example, let’s first define our array.

Now let’s write our each statement

In the above code, we’re telling our predefined array to do some function and we’re passing each value of the array into the function through the parameter ‘i’.

For more information about ruby’s each method, refer to the link below.
http://perl.about.com/od/rubytutorials/a/rubyeachloop.htm

Enhanced by Zemanta