agardiner/csv-diff

Rows are never split on commas?

kotyy opened this issue · 3 comments

I'm fairly new to ruby, but on lines 121 and 125 of csv_source.rb, shouldn't you split the row and field_vals variables by a comma?

Without that, the row and field_vals variables were set to the comma-separated string for a given row, i.e. foo,bar,1,2,3, which caused issues with the following each_with_index and map calls.

The index_source method expects to be passed an array of arrays, not an array of strings - see the comment at the start of the method.

How are you using this method? Are you working with a source other than CSV flles?

Thanks for your reply. Looking at it today, it was pretty easy to see the issue. I was using File.open(path) not CSV.open(path). Opening the file with the CSV class, as you mentioned above, provides an array of arrays, not an array of strings.

May I suggest a modification to the initialize method in csv_source to make it a bit more stupid-proof?

            unless source.is_a?(CSV)
                raise ArgumentError, "source should be of class 'CSV'", caller
            end

The interface is deliberately open in what it will accept - not just CSV, but anything that yields an array of arrays. For example, one other use case I have used is diffing off of SQL query results.
That said, I can certainly add a check and a more helpful error message.

Cheers!