Initially I have am empty csv file on my computer. I start with this piece of code:
CSV.open("GreenTea.csv", "wb") do |csv|
csv << ["ObjectID", "PropertyID", "PropertyValue", "SourceID"]
end
This does its job right and writes this into the file. Later on I made a struct and would like to convert it into csv so I did this:
....
current = info.new
current.ObjectID = text[0] #Green tea
current.PropertyID = nil #Relation
current.PropertyValue = text[1] #description of antioxidant
current.SourceID = a['href'] #source extracted by clubweb
CSV.open("GreenTea.csv", "wb") do |csv|
csv << [current.ObjectID, current.PropertyID, current.PropertyValue, current.SourceID]
end
end
However when I check the file again, I only see this:
It seems like the info is being overwritten by the very last info in the loop! How can i prevent this? i want to keep adding into the file not overwrite.