Sha256: 945b3975fdbe233fb2908048b638a2ad4fb7c68fb109b2a8b30494d339ccf7d8

Contents?: true

Size: 961 Bytes

Versions: 33

Compression:

Stored size: 961 Bytes

Contents

require 'csv'

module Eco
  class CSV < ::CSV

    class << self

      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

      def read(file, **kargs)
        kargs = {headers: true,  skip_blanks: true}.merge(kargs)

        args = [file].tap do |arg|
          coding = Eco::API::Common::Session::FileManager.encoding(file)
          arg.push("rb:bom|utf-8") if coding == "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

33 entries across 33 versions & 1 rubygems

Version Path
eco-helpers-2.0.18 lib/eco/csv.rb
eco-helpers-2.0.17 lib/eco/csv.rb
eco-helpers-2.0.16 lib/eco/csv.rb
eco-helpers-2.0.15 lib/eco/csv.rb
eco-helpers-2.0.14 lib/eco/csv.rb
eco-helpers-2.0.13 lib/eco/csv.rb
eco-helpers-2.0.12 lib/eco/csv.rb
eco-helpers-2.0.11 lib/eco/csv.rb
eco-helpers-2.0.10 lib/eco/csv.rb
eco-helpers-2.0.9 lib/eco/csv.rb
eco-helpers-2.0.8 lib/eco/csv.rb
eco-helpers-2.0.7 lib/eco/csv.rb
eco-helpers-2.0.6 lib/eco/csv.rb
eco-helpers-2.0.5 lib/eco/csv.rb
eco-helpers-2.0.4 lib/eco/csv.rb
eco-helpers-2.0.3 lib/eco/csv.rb
eco-helpers-2.0.2 lib/eco/csv.rb
eco-helpers-1.5.15 lib/eco/csv.rb
eco-helpers-1.5.14 lib/eco/csv.rb
eco-helpers-1.5.13 lib/eco/csv.rb