Sha256: 6ecc1f12e66468e68b33529b9c7d6437c2f74264642396a95c368131b7564153
Contents?: true
Size: 1.12 KB
Versions: 41
Compression:
Stored size: 1.12 KB
Contents
require 'csv' module Eco class CSV < ::CSV class << self # @return [Eco::CSV::Table] def parse(data, **kargs, &block) kargs = {headers: true, skip_blanks: true}.merge(kargs) out = super(data, **kargs, &block).reject do |row| values = row.to_hash.values values.all?(&:nil?) || values.map(&:to_s).all?(&:empty?) end Eco::CSV::Table.new(out) end # @return [Eco::CSV::Table] def read(file, **kargs) kargs = {headers: true, skip_blanks: true}.merge(kargs) args = [file].tap do |arg| encoding = Eco::API::Common::Session::FileManager.encoding(file) #encoding = (encoding != "utf-8")? "#{encoding}|utf-8": encoding #arg.push(encoding) arg.push("rb:bom|utf-8") if encoding == "bom" end out = super(*args, **kargs).reject do |row| values = row.to_hash.values values.all?(&:nil?) || values.map(&:to_s).all?(&:empty?) end Eco::CSV::Table.new(out) end end end end require_relative 'csv/table'
Version data entries
41 entries across 41 versions & 1 rubygems