lib/peddler/flat_file_parser.rb in peddler-2.1.1 vs lib/peddler/flat_file_parser.rb in peddler-2.3.0

- old
+ new

@@ -4,11 +4,11 @@ require 'csv' require 'digest/md5' require 'peddler/headers' module Peddler - # @api private + # @!visibility private class FlatFileParser < SimpleDelegator include Headers # http://stackoverflow.com/questions/8073920/importing-csv-quoting-error-is-driving-me-nuts OPTIONS = { col_sep: "\t", quote_char: "\x00", headers: true }.freeze @@ -21,11 +21,11 @@ scrub_body!(encoding) extract_content_and_summary end def parse(&blk) - CSV.parse(content, OPTIONS, &blk) unless content.empty? + CSV.parse(content, **OPTIONS, &blk) unless content.empty? end def records_count summarize if summary end @@ -42,10 +42,12 @@ self.body = body.dup.force_encoding(content_charset || encoding) end def extract_content_and_summary @content = body.encode('UTF-8', invalid: :replace, undef: :replace) - @summary, @content = @content.split("\n\n", 2) if @content =~ /\t\t.*\n\n/ + return unless @content.match?(/\t\t.*\n\n/) + + @summary, @content = @content.split("\n\n", 2) end def summarize Hash[summary.split("\n\t")[1, 2].map { |line| line.split("\t\t") }] end