#!/usr/bin/env ruby
#-*- coding: utf-8 -*-
require 'csv'

data = CSV.read("landry_quiz.csv", :headers => true)
template_quiz = File.read("template_quiz.html")
template_seikai = File.read("template_seikai.html")
template_huseikai = File.read("template_huseikai.html")
data.each do |row|
  quiz_file = sprintf("quiz%d.html", row["_number_"])
  seikai_file = sprintf("seikai%d.html", row["_number_"])
  huseikai_file = sprintf("huseikai%d.html", row["_number_"])
  tango = row
  open(quiz_file,"w") {|html| html.print template_quiz.gsub(/_[A-Z]+_/i, tango)}
  open(seikai_file,"w") {|html| html.print template_seikai.gsub(/_[A-Z]+_/i, tango)}
  open(huseikai_file,"w") {|html| html.print template_huseikai.gsub(/_[A-Z]+_/i, tango)}
end
