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'