Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created Feb 3, 2019
Embed
What would you like to do?
#!/usr/bin/env ruby
# Usage
# $ ruby tools/table.rb
require 'terminal-table'
def make_table rank
headings = [ rank.upcase ]
qs = eval(File.read("tools/#{rank}.txt")).to_a
rows = qs.map { |q|
[q]
}
exts = Dir["#{rank}*"].map { |f|
File.extname(f)
}.uniq
exts.each do |ext|
headings << ext
rows.each do |row|
q = row[0]
if File.exists?("#{q}#{ext}") or File.exists?("#{q}#{ext}".downcase)
row << q
else
row << nil
end
end
end
table = Terminal::Table.new do |t|
t.headings = headings
t.rows = rows
end
end
%w[d c b a s].each do |rank|
table = make_table rank
puts table
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment