Rather than looking for the input SPARQL query and CSV URL in template parameters and trying to parse them out with a regex, this switches to using subpages for those inputs. This also switches to writing the comparison and stats to separate subpages.
There are quite a few benefits to using subpages:
More of the logic can live in wikitext templates, rather than in Ruby-land.
SPARQL queries and CSV URLs can themselves be templated to reduce duplication.
The output can just be overwritten, rather than finding the appropriate part of the page to write the output to.
Allows for easier customisation of the output if you only want to include certain parts of the prompt page.
Rather than looking for the input SPARQL query and CSV URL in template parameters and trying to parse them out with a regex, this switches to using subpages for those inputs. This also switches to writing the comparison and stats to separate subpages.
There are quite a few benefits to using subpages: