Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created February 3, 2019 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyanny/efee6772c3e79f94f001752c2576e6b4 to your computer and use it in GitHub Desktop.
Save kyanny/efee6772c3e79f94f001752c2576e6b4 to your computer and use it in GitHub Desktop.
#!/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