Created
February 3, 2019 15:07
-
-
Save kyanny/efee6772c3e79f94f001752c2576e6b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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