From 90ed96d524f092373e186f241eccf69c5f2b7c63 Mon Sep 17 00:00:00 2001 From: Wilfried OLLIVIER Date: Thu, 5 Aug 2021 14:23:30 +0200 Subject: [PATCH] Add savage tool --- .gitignore | 1 + savage.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 .gitignore create mode 100644 savage.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1fcb152 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +out diff --git a/savage.rb b/savage.rb new file mode 100644 index 0000000..05c3e8e --- /dev/null +++ b/savage.rb @@ -0,0 +1,21 @@ +require 'optparse' + +options = { input: 'input', output: 'out', tracks: 40, generate: 0 } +OptionParser.new do |opts| + opts.banner = 'savage blind test generator' + + opts.on('-i', '--input=FOLDER', 'select input folder') do |i| + options[:input] = i + end +end.parse! + +entries = [] +Dir["#{options[:input]}/*.csv"].each do |path| + entries.concat(File.readlines(path).select { |l| !l.start_with?('#') && !l.start_with?('!') }) +end + +entries.shuffle! + +(0..options[:generate]).each do |index| + File.open("#{options[:output]}/#{index}.csv", 'w') { |f| f.write(entries.sample(options[:tracks]).join('')) } +end