lib/eco/api/usecases/default/utils/split_csv_case.rb in eco-helpers-2.7.16 vs lib/eco/api/usecases/default/utils/split_csv_case.rb in eco-helpers-2.7.17
- old
+ new
@@ -5,28 +5,48 @@
name "split-csv"
type :other
def main(*_args)
- Eco::CSV.split(input_file, max_rows: max_rows).each do |file|
- log(:info) {
- "Generated file '#{file}'"
- }
+ if simulate?
+ count = Eco::CSV.count(input_file, start_at: start_at)
+ log(:info) { "CSV '#{input_file}' has #{count} rows." }
+ else
+ Eco::CSV.split(
+ input_file,
+ max_rows: max_rows,
+ start_at: start_at,
+ &filter
+ ).each do |file|
+ log(:info) { "Generated file '#{file}'" }
+ end
end
end
private
+ def filter
+ nil
+ end
+
def input_file
options.dig(:source, :file)
end
def max_rows
max_rows_options || self.class::MAX_ROWS
end
def max_rows_options
return nil unless (num = options.dig(:output, :file, :max_rows))
+
+ num = num.to_i
+ num = nil if num.zero?
+ num
+ end
+
+ def start_at
+ return nil unless (num = options.dig(:output, :file, :start_at))
num = num.to_i
num = nil if num.zero?
num
end