Class: Eco::CSV::Split
- Includes:
- Language::AuxiliarLogger
- Defined in:
- lib/eco/csv/split.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
-
#call {|idx, file| ... } ⇒ Array<String>
Names of the generated files.
-
#copy_count ⇒ Integer
Number of total output rows.
-
#initialize(filename, max_rows:, start_at: nil, **kargs) ⇒ Split
constructor
A new instance of Split.
-
#out_files ⇒ Array<String>
List of created files.
-
#total_count ⇒ Integer
Number of total input rows.
Methods included from Language::AuxiliarLogger
Constructor Details
#initialize(filename, max_rows:, start_at: nil, **kargs) ⇒ Split
Returns a new instance of Split.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/eco/csv/split.rb', line 8 def initialize(filename, max_rows:, start_at: nil, **kargs) msg = "File '#{filename}' does not exist" raise ArgumentError, msg unless ::File.exist?(filename) @filename = filename @max_rows = max_rows @start_at = start_at @params = kargs init end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/eco/csv/split.rb', line 6 def filename @filename end |
Instance Method Details
#call {|idx, file| ... } ⇒ Array<String>
Returns names of the generated files.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/eco/csv/split.rb', line 41 def call(&block) stream.for_each(start_at_idx: start_at) do |row, ridx| self.total_count += 1 copy_row(row, ridx, &block) end out_files ensure puts "Close at row #{row_idx}" @csv&.close end |
#copy_count ⇒ Integer
Returns number of total output rows.
21 22 23 |
# File 'lib/eco/csv/split.rb', line 21 def copy_count @copy_count ||= 0 end |
#out_files ⇒ Array<String>
Returns list of created files.
31 32 33 |
# File 'lib/eco/csv/split.rb', line 31 def out_files @out_files ||= [] end |
#total_count ⇒ Integer
Returns number of total input rows.
26 27 28 |
# File 'lib/eco/csv/split.rb', line 26 def total_count @total_count ||= 0 end |