Numismatic charm & 2020 New England Black Wolves season

This commit is contained in:
nik gaffney 2020-11-10 16:11:15 +01:00
parent a4f1ae9dde
commit d4dd5aa858
2 changed files with 76 additions and 14 deletions

Binary file not shown.

90
cards/preprocess.rb Normal file → Executable file
View file

@ -1,17 +1,60 @@
#!/usr/bin/env ruby -w
# input mode can be "txt" or "ods"
$input = "ods"
require 'optparse'
require 'ostruct'
require 'pp'
require 'roo'
# convert text files into .csv for deck.rb mogrification
$cards_csv = "cards.csv"
# command line options
class Optparsec
# Return a structure describing the options.
def self.parse(args)
# The options specified on the command line will be collected in *options*.
# set default values here.
options = OpenStruct.new
options.input_file = "cards.ods"
options.output_file = "cards.csv"
options.input_type = "ods"
options.verbose = true
# card descriptions in textfiles
$cards_o = "cards-occasions.txt"
$cards_q = "cards-qualifiers.txt"
$cards_v = "cards-verbs.txt"
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: example.rb [options]"
opts.separator ""
opts.separator "Specific options:"
# all card descriptions in a single spreadsheet
$cards_ods = "cards.ods"
opts.on("-i", "--input FILE", "Input file") do |i|
options.input_file = i
end
opts.on("-o", "--output FILE", "Output file (csv)") do |i|
options.input_file = i
end
# type of input file (can also check extension)
opts.on("-t", "--type [TYPE]", ["ods", "csv", "txt"],
"Input type (ods, csv or txt)") do |t|
options.input_type = t
end
opts.on("-v", "--[no-]verbose", "Verbosity") do |v|
options.verbose = v
end
# help and/or no opts
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end
opt_parser.parse!(args)
options
end # parse()
end # class OptparseExample
options = Optparsec.parse(ARGV)
if options.verbose
puts "reading from file: " + options.input_file
puts "assuming input is: " + options.input_type
puts "results output to: " + options.output_file
puts "..."
end
# assuming an .ods file laid out as follows
#
@ -19,7 +62,22 @@ $cards_ods = "cards.ods"
# col 2 - qualifiers
# col 3 - verbs
ods = Roo::OpenOffice.new($cards_ods)
case options.input_type
when "ods"
# all card descriptions in a single spreadsheet
ods = Roo::OpenOffice.new(options.input_file)
when "txt"
# card descriptions in textfiles
$cards_o = "cards-occasions.txt"
$cards_q = "cards-qualifiers.txt"
$cards_v = "cards-verbs.txt"
else
puts "input format not supported."
exit
end
# convert text files into .csv for deck.rb mogrification
$cards_csv = options.output_file
# preamble...
File.open($cards_csv, "w")
@ -40,18 +98,22 @@ def write_verb(line)
File.write($cards_csv, "#{line},V,...,img/v_card.svg\n", mode: "a")
end
case $input
# read descriptions and write to file...
case options.input_type
when "txt"
# read descriptions and write to file...
puts "reading descriptions from text files" if options.verbose
File.foreach($cards_o) { |line| write_occasion line.chomp }
File.foreach($cards_q) { |line| write_qualifier line.chomp }
File.foreach($cards_v) { |line| write_verb line.chomp }
when "ods"
# read descriptions and write to file...
puts "reading descriptions from ods file: " + options.input_file if options.verbose
ods.column(1).each { |line| write_occasion line.chomp }
ods.column(2).each { |line| write_qualifier line.chomp }
ods.column(3).each { |line| write_verb line.chomp }
else
puts "input format not supported."
exit
end
puts "written out to file: " + options.output_file if options.verbose