Class: Eco::CSV::Split
- Includes:
- Language::AuxiliarLogger
- Defined in:
- lib/eco/csv/split.rb
Instance Attribute Summary collapse
-
#copy_count ⇒ Integer
Number of total output rows.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#total_count ⇒ Integer
Number of total input rows.
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
-
#call {|idx, file| ... } ⇒ Array<String>
Names of the generated files.
-
#initialize(filename, max_rows:, start_at: nil, **kargs) ⇒ Split
constructor
A new instance of Split.
-
#out_files ⇒ Array<String>
List of created files.
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
#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 |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/eco/csv/split.rb', line 6 def filename @filename end |
#total_count ⇒ Integer
Returns number of total input rows.
27 28 29 |
# File 'lib/eco/csv/split.rb', line 27 def total_count @total_count ||= 0 end |
Instance Method Details
#call {|idx, file| ... } ⇒ Array<String>
Returns names of the generated files.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/eco/csv/split.rb', line 43 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 |
#out_files ⇒ Array<String>
Returns list of created files.
33 34 35 |
# File 'lib/eco/csv/split.rb', line 33 def out_files @out_files ||= [] end |