Class: Eco::CSV

Inherits:
CSV show all
Extended by:
Data::Files
Defined in:
lib/eco/csv.rb,
lib/eco/csv/split.rb,
lib/eco/csv/table.rb,
lib/eco/csv/stream.rb

Defined Under Namespace

Classes: Split, Stream, Table

Constant Summary

Constants included from Data::Files

Data::Files::DEFAULT_TIMESTAMP_PATTERN

Constants included from Data::Files::Encoding

Data::Files::Encoding::BOM_BYTES

Instance Attribute Summary

Attributes included from Language::AuxiliarLogger

#logger

Class Method Summary collapse

Methods included from Data::Files::ClassMethods

#copy_file, #create_directory, #csv_files, #dir_exists?, #file_basename, #file_empty?, #file_exists?, #file_fullpath, #file_name, #file_path, #folder_files, #script_subfolder, #split, #timestamp, #timestamp_file

Methods included from Data::Files::Encoding

#encoding, #file_empty?, #file_exists?, #get_file_content_with_encoding, #has_bom?, #remove_bom, #scoped_encoding

Methods included from Language::AuxiliarLogger

#log

Methods included from Data::Files::InstanceMethods

#get_file_content, #read_with_tolerance

Class Method Details

.parse(data, **kargs, &block) ⇒ Eco::CSV::Table

Returns:



8
9
10
11
# File 'lib/eco/csv.rb', line 8

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

.read(file, **kargs) ⇒ Eco::CSV::Table

Returns:



14
15
16
17
18
19
# File 'lib/eco/csv.rb', line 14

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

.split(filename, max_rows:, **kargs) {|idx, file| ... } ⇒ Object

Parameters:

  • filename (String)

    the orignal file

  • max_rows (Integer)

    number of rows per file

Yields:

  • (idx, file)

    a block to spot the filename

Yield Parameters:

  • idx (Integer)

    the number of the file

  • file (String)

    the default name of the file

Yield Returns:

  • (String)

    the filename of the file idx.

    • If nil it will create its own filename convention

See Also:



29
30
31
# File 'lib/eco/csv.rb', line 29

def split(filename, max_rows:, **kargs, &block)
  Eco::CSV::Split.new(filename, max_rows: max_rows, **kargs).call(&block)
end