CaHGen: A Cards Against Humanity generator in ruby and prawn
Cards Against Humanity is a terrible game that has instant appeal and is liberally licensed, which is nice. Some time back a group of friends and I constructed our own, modified, deck, based on the fact that:
- We don’t get half the US-centric jokes in the deck
- We don’t enjoy poop jokes quite as much as the authors
Our original set was hand-written on torn-up bits of printer paper, but I decided that if we were going to do this properly we should print some out. My first attempt involved Microsoft Word’s label program, but I quickly determined that I could make the whole thing incredibly geekier by using Prawn to turn a text file into a PDF, ready for printing.
So that’s what I did. You can grab the code here, and you can see the results in the banner above.
Running it yourself
Once you’ve installed
cahgen (it needs the gems
trollop, but that’s it), all you need to do is make a plaintext file of questions and answers. Here’s the sort of thing I’m talking about:
1 2 3 4 5 6 7
Vigilante justice. Three-ply toilet paper. Letting everyone down. Self-loathing. Blood.\\So much blood. Universal fear and terror. Hundred of bees.
You can use backslashes to indicate newlines (so the above answer card for “blood” takes up two lines, with a one-line break in the middle). Other than that, you can’t do any formatting, but I haven’t seen an “official” Card Against Humanity with formatting, so I’m sure you’ll manage.
Output goes to
output.pdf, ready for printing. Our home printer is a somewhat senescent HP Photosmart that doesn’t support duplex, so the actual process of printing (i.e. feeding in card-stock, one sheet at a time, and putting just-printed pages back in the printer to do the other side) is the most labour-intensive part of this process.
Identifying a pattern
Prawn is an amazing tool for generating PDFs. In fact, since making the above code for CaH I’ve built a simple letter generator for the inevitable post-Christmas correspondence to overseas relatives. I would usually write these letters in Pages, but it’s always been a case of using the “least-worst” word processor available (and in my mind, Pages ‘11 is a UI downgrade from '09). Now I can write the letter up in my favourite text editor and convert to a fully-formatted, properly-dated, well-addressed letter in seconds.
I feel that this is an emergent pattern: replacing word processor tasks with text editor tasks, followed by conversion of plaintext to PDF. Now I’ve identified the pattern, I’m interested to see if there’s any other tasks in my life I can convert.