Monday, October 22, 2007

csv in ruby




A nice little CSV in Ruby. I had rolled my own simple CSV parser, but when I ran into some more tricky situations, I switched to this CSV Library and handled the edge cases.

I wanted to just parse a single line of CSV, so I use:


CSV::Reader.parse(line)
s = CSV.parse_line(line)
self.upc_code = s[0]
self.code = s[1]
self.brand_name = s[2]