Class: Eco::CSV
- 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
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
Class Method Summary collapse
-
.count(filename, start_at: nil, **kargs) ⇒ Integer
The number of rows of the file.
- .parse(data, **kargs) ⇒ Eco::CSV::Table
- .read(file, **kargs) ⇒ Eco::CSV::Table
-
.split(filename, max_rows:, start_at: nil, **kargs) {|row, ridx, fidx, file| ... } ⇒ Eco::CSV::Split
Splits the csv
filename
intomax_rows
.
Methods included from Data::Files::ClassMethods
#copy_file, #create_directory, #csv_files, #dir_exists?, #file_basename, #file_empty?, #file_exists?, #file_fullpath, #file_name, #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
Methods included from Data::Files::InstanceMethods
#get_file_content, #read_with_tolerance
Class Method Details
.count(filename, start_at: nil, **kargs) ⇒ Integer
Note:
it excludes headers by default
Returns the number of rows of the file.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/eco/csv.rb', line 46 def count(filename, start_at: nil, **kargs) count = 0 streamer = Eco::CSV::Stream.new(filename, **kargs) streamer.for_each(start_at_idx: start_at) do |row| included = true included = yield(row) if block_given? count += 1 if included end count end |
.parse(data, **kargs) ⇒ Eco::CSV::Table
8 9 10 11 |
# File 'lib/eco/csv.rb', line 8 def parse(data, **kargs) kargs = {headers: true, skip_blanks: true}.merge(kargs) Eco::CSV::Table.new(super) end |
.read(file, **kargs) ⇒ Eco::CSV::Table
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:, start_at: nil, **kargs) {|row, ridx, fidx, file| ... } ⇒ Eco::CSV::Split
Splits the csv filename
into max_rows
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/eco/csv.rb', line 33 def split(filename, max_rows:, start_at: nil, **kargs, &block) Eco::CSV::Split.new( filename, max_rows: max_rows, start_at: start_at, **kargs ).tap do |splitter| splitter.call(&block) end end |