Class: Eco::CSV::Split
- Includes:
- Language::AuxiliarLogger
- Defined in:
- lib/eco/csv/split.rb
Constant Summary collapse
- MAX_ROWS_DEFAULT =
1_000_000
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 {|row, ridx, fidx, file| ... } ⇒ Array<String>
Names of the generated files.
-
#initialize(filename, max_rows: :unused, 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: :unused, start_at: nil, **kargs) ⇒ Split
Returns a new instance of Split.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/eco/csv/split.rb', line 10 def initialize(filename, max_rows: :unused, start_at: nil, **kargs) msg = "File '#{filename}' does not exist" raise ArgumentError, msg unless ::File.exist?(filename) @filename = filename @max_rows = max_rows @max_rows = MAX_ROWS_DEFAULT if max_rows == :unused @start_at = start_at @params = kargs init end |
Instance Attribute Details
#copy_count ⇒ Integer
Returns number of total output rows.
24 25 26 |
# File 'lib/eco/csv/split.rb', line 24 def copy_count @copy_count ||= 0 end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
8 9 10 |
# File 'lib/eco/csv/split.rb', line 8 def filename @filename end |
#total_count ⇒ Integer
Returns number of total input rows.
30 31 32 |
# File 'lib/eco/csv/split.rb', line 30 def total_count @total_count ||= 0 end |
Instance Method Details
#call {|row, ridx, fidx, file| ... } ⇒ Array<String>
Returns names of the generated files.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/eco/csv/split.rb', line 47 def call(&filter) stream.for_each(start_at_idx: start_at) do |row, ridx| self.total_count += 1 copy_row(row, ridx, &filter) end out_files ensure puts "Close at row #{row_idx}" @csv&.close end |
#out_files ⇒ Array<String>
Returns list of created files.
36 37 38 |
# File 'lib/eco/csv/split.rb', line 36 def out_files @out_files ||= [] end |