I am brand new to Ruby and using it to try to read/write to csv. So far, I have a script that does the following:
- Imports data from a CSV file, storing select columns as a separate array (I don't need data from every column)
- Performs calculations on the data, stores the results in newly created arrays
Transposes the arrays to table rows, to be outputted to a csv
table = [Result1, Result2, Result3].transpose
Currently, I am able to output the table using the following:
CSV.open(resultsFile, "wb", :write_headers=> true, :headers => ["Result1", "Result2", "Result3"] ) do |csv| table.each do |row| csv << row end
My question is, how can I add a conditional to only output rows where one of the results equals a certain text string. For example, if the value in result2 is equal to "Apple", I want the data in that row to be written to the csv file. If not, then skip that row.
I've tried placing if/else in a few different areas and have not had any success.
Thanks for any help