lib/cevennes.rb in cevennes-1.2.0 vs lib/cevennes.rb in cevennes-1.3.0
- old
+ new
@@ -3,11 +3,11 @@
require 'csv'
module Cevennes
- VERSION = '1.2.0'
+ VERSION = '1.3.0'
class << self
def diff(id, csv0, csv1, opts={})
@@ -58,11 +58,11 @@
def hash(version, id, csv, opts)
d = opts[:ignore_key_case] ? DOWNCASE : IDENTITY
did = d[id]
- csva = ::CSV.parse(reencode(csv))
+ csva = parse(csv)
.each_with_index.collect { |row, i| [ 1 + i, strip(row) ] }
.reject { |i, row| row.compact.empty? }
.drop_while { |i, row| ! row.find { |cell| d[cell] == did } }
fail ::IndexError.new("id #{id.inspect} not found in #{version} CSV") \
@@ -80,9 +80,15 @@
if row.compact.length > 1
k = row[idi]
h[k] = [ i, row ] if k
end
h }
+ end
+
+ def parse(csv)
+
+ return csv if csv.is_a?(Array)
+ ::CSV.parse(reencode(csv))
end
#def deflate(row)
# ::CSV.generate(encoding: 'UTF-8') { |csv| csv << row }.strip
#end