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::Timestamp
Data::Files::Timestamp::DEFAULT_TIMESTAMP
Constants included from Data::Files::Folder
Data::Files::Folder::PRESERVED_FILES
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
filenameintomax_rows.
Methods included from Data::Files::ClassMethods
Methods included from Data::Files::RelativePath
Methods included from Data::Files::Timestamp
Methods included from Data::Files::Folder
#archive_file, #clear_folder, #csv_files, #ensure_file_path!, #ensure_folder!, #folder_files
Methods included from Language::AuxiliarLogger
Methods included from Data::Files::Encoding
#bom?, #encoding, #get_file_content_with_encoding, #remove_bom, #scoped_encoding
Methods included from Data::Files::Content
#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 |