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

Version Path
eco-helpers-2.0.66 lib/eco/csv.rb
eco-helpers-2.0.65 lib/eco/csv.rb
eco-helpers-2.0.64 lib/eco/csv.rb
eco-helpers-2.0.63 lib/eco/csv.rb
eco-helpers-2.0.62 lib/eco/csv.rb
eco-helpers-2.0.61 lib/eco/csv.rb
eco-helpers-2.0.60 lib/eco/csv.rb
eco-helpers-2.0.59 lib/eco/csv.rb
eco-helpers-2.0.58 lib/eco/csv.rb
eco-helpers-2.0.57 lib/eco/csv.rb
eco-helpers-2.0.56 lib/eco/csv.rb
eco-helpers-2.0.55 lib/eco/csv.rb
eco-helpers-2.0.54 lib/eco/csv.rb
eco-helpers-2.0.53 lib/eco/csv.rb
eco-helpers-2.0.52 lib/eco/csv.rb
eco-helpers-2.0.51 lib/eco/csv.rb
eco-helpers-2.0.50 lib/eco/csv.rb
eco-helpers-2.0.49 lib/eco/csv.rb
eco-helpers-2.0.48 lib/eco/csv.rb
eco-helpers-2.0.47 lib/eco/csv.rb