Skip to content

Instantly share code, notes, and snippets.

@tatey tatey/00_cli
Created May 17, 2019

What would you like to do?
Federal Election 2019 Bingo Card Generator in Ruby
$ ruby 01_bingo.rb > ~/Downloads/board_1.html
require "erb"
class Cell <, :party, :margin, :trivia)
class Board
def initialize(cells)
@rows = cells.shuffle[0..8].each_with_index.reduce([]) do |rows, (cell, index)|
cols = (rows[index % 3] ||= [])
cols << cell
def generate<<-HTML
<!DOCTYPE html>
<meta charset="utf8"/>
<style type="text/css">
body {
font-family: sans-serif;
table {
border-collapse: collapse;
width: 100%;
table-layout: fixed;
td {
border: 1px solid #000;
text-align: center;
padding: 5pt;
height: 150px;
.title {
font-size: 16pt;
font-weight: bold;
display: block;
.subtitle {
font-size: 12pt;
display: block;
.body {
font-size: 12pt;
display: block;
.party-alp .title,
.party-alp .subtitle {
color: red;
.party-lnp .title,
.party-lnp .subtitle {
color: blue;
.party-nat .title,
.party-nat .subtitle {
color: green;
<h1>Election Party 2019 🎉</h1>
<% @rows.each do |cols| %>
<% cols.each do |col| %>
<td class="party party-<%= %>">
<span class="title"><%= %></span>
<span class="subtitle"><%= %> <%= col.margin %></span>
<span class="body"><%= col.trivia %></span>
<% end %>
<% end %>
board =["Herbert", "ALP", "0.03%", "Cathy O'Toole was declared the winner by 37 votes"),"Indi", "IND", "5.5%", "Kathy McGowan and the 'Voices for Indi' group are backing new candidate Dr Helen Haines"),"Dawson", "LNP", "3.4%", "George Christensen AKA the MP for Manila"),"Dickson", "LNP", "1.7%", "Ali France VS Peter Dutton"),"Warringah", "LNP", "11.7%", "Staggall VS Tony Abbott"),"Wentworth", "IND", "1.0%", "Independent Dr Kerryn Phelps at the by-election following the resignation of Malcolm Turnbull"),"Cowper", "NAT", "4.6%", "Oakeshott's shot against retiring MP"),"Sturt", "LNP", "5.4%", "Chris Pyne is retiring"),"Pearce", "LNP", "3.6", "Attorney-General Christian Porter had a big swing against him in the last election"),"Higgans", "LNP", "7.4%", "The retiring Liberal MP is Kelly O'Dwyer. Minister for Jobs, Industrial Relations and Women."),"Kooyong", "LNP", "12.8%", "Treasurer Josh Frydenburg VS Julian Burnside QC"),"Hasluck", "LNP", "2.1%", "Aged Care Minister Ken Wyatt faces a tough contest"),"Canning", "LNP", "6.8%", "A very bad result would also put Andrew Hastie at risk"),"Eden-Monaro", "ALP", "2.9%", "Bellweather"),"Lindsay", "ALP", "1.1%", "Bellweather"),"Macquarie", "ALP", "2.2%", "Bellweather"),"Bass", "ALP", "5.4%", "Always votes out the incumbent"),"Longman", "ALP", "0.8%", "Susan Lamb retained this seat in the Super Saturday by-elections"),"Corangamite", "ALP", "0.03%", "$26,500 per person worth of pork barrelling by the LNP"),"Forde", "LNP", "0.6%", "Bert van Manen has been visiting local communities with super sized carboard cheques"),
puts board.generate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.