superject/cards/preprocess.rb

57 lines
1.5 KiB
Ruby

# input mode can be "txt" or "ods"
$input = "ods"
# convert text files into .csv for deck.rb mogrification
$cards_csv = "cards.csv"
# card descriptions in textfiles
$cards_o = "cards-occasions.txt"
$cards_q = "cards-qualifiers.txt"
$cards_v = "cards-verbs.txt"
# all card descriptions in a single spreadsheet
$cards_ods = "cards.ods"
# assuming an .ods file laid out as follows
#
# col 1 - occasions
# col 2 - qualifiers
# col 3 - verbs
ods = Roo::OpenOffice.new($cards_ods)
# preamble...
File.open($cards_csv, "w")
File.write($cards_csv, "name,type,text,illustration\n", mode: "w")
# Occasions
def write_occasion(line)
File.write($cards_csv, "#{line},O,...,img/o_card.svg\n", mode: "a")
end
# Qualifiers
def write_qualifier(line)
File.write($cards_csv, "#{line},Q,...,img/q_card.svg\n", mode: "a")
end
# Verbs
def write_verb(line)
File.write($cards_csv, "#{line},V,...,img/v_card.svg\n", mode: "a")
end
case $input
when "txt"
# read descriptions and write to file...
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...
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."
end