splittable: klare Fehler für -0 und mehr als 676 Stücke
This commit is contained in:
@@ -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 ------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user