splittable: klare Fehler für -0 und mehr als 676 Stücke

This commit is contained in:
wkh
2026-10-11 23:23:37 +02:00
parent 1c66773ff4
commit b11e3da453
6 changed files with 36 additions and 4 deletions
+6 -4
View File
@@ -164,12 +164,14 @@ end
Rdb.register('splittable', 'Divide a table horizontally', 'splittable [-n] table') do |args|
n = 50
n = args.shift[1..].to_i if args.first&.match?(/\A-\d+\z/)
die 'usage: splittable [-n] table' unless args.size == 1
die 'usage: splittable [-n] table (n is at least 1)' unless args.size == 1 && n.positive?
t = open_table(args[0])
chunks = t.rows.each_slice(n).to_a
die "#{args[0]}: #{t.rows.size} rows in pieces of #{n} need #{chunks.size} files, but there are only 676 names (aa to zz)" if chunks.size > 676
suffix = ('aa'..'zz').each
t.rows.each_slice(n) do |chunk|
File.write("#{args[0]}#{suffix.next}", t.with(rows: chunk).to_s)
end
chunks.each { |chunk| File.write("#{args[0]}#{suffix.next}", t.with(rows: chunk).to_s) }
end
# ---- aggregates ------------------------------------------------------------