Sha256: 3a1a3cc67d6b9d22e87286c83c9dd1bfb46199253c7f93cff9dd5e6de4a5f011
Contents?: true
Size: 845 Bytes
Versions: 5
Compression:
Stored size: 845 Bytes
Contents
require 'delegate' require 'csv' require 'digest/md5' module Peddler # @api private class CSVParser < SimpleDelegator attr :content, :summary def initialize(res) super(res) split_body end def parse # http://stackoverflow.com/questions/8073920/importing-csv-quoting-error-is-driving-me-nuts CSV.parse(content, col_sep: "\t", quote_char: "\x00", headers: true) if content end def records_count Hash[summary.split("\n\t")[1, 2].map { |line| line.split("\t\t") }] end def valid? headers['Content-MD5'] == Digest::MD5.base64digest(body) end private def split_body @summary, @content = body.split("\n\n") end def scrub_content content.force_encoding(encoding).encode('UTF-8') end def encoding 'ISO-8859-1' end end end
Version data entries
5 entries across 5 versions & 1 rubygems