Sha256: 12983aa8360647cb279f3491c68e976f746cd428919d304b914796c5a225c2a1

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 KB

Contents

require 'csv'
module Eco
  class CSV < ::CSV
    class << self
      include Eco::Data::Files

      # @return [Eco::CSV::Table]
      def parse(data, **kargs, &block)
        kargs = {headers: true, skip_blanks: true}.merge(kargs)
        Eco::CSV::Table.new(super(data, **kargs, &block))
      end

      # @return [Eco::CSV::Table]
      def read(file, **kargs)
        params = {}.tap do |prms|
          prms.merge!(encoding: kargs.delete(:encoding)) if kargs.key?(:encoding)
        end
        parse(get_file_content(file, **params), **kargs)
      end

      # @yield [idx, file] a block to spot the filename
      # @yieldparam idx [Integer] the number of the file
      # @yieldparam file [String] the default name of the file
      # @yieldreturn [String] the filename of the file `idx`.
      #   - If `nil` it will create its own filename convention
      # @param filename [String] the orignal file
      # @param max_rows [Integer] number of rows per file
      # @see Eco::CSV::Split#call
      def split(filename, max_rows:, **kargs, &block)
        Eco::CSV::Split.new(filename, max_rows: max_rows, **kargs).call(&block)
      end
    end
  end
end

require_relative 'csv/table'
require_relative 'csv/stream'
require_relative 'csv/split'

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eco-helpers-2.7.16 lib/eco/csv.rb
eco-helpers-2.7.15 lib/eco/csv.rb
eco-helpers-2.7.14 lib/eco/csv.rb
eco-helpers-2.7.13 lib/eco/csv.rb