Skip to content

Instantly share code, notes, and snippets.

@tatey
Created May 17, 2019 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatey/6354af3aeacd00e8c488ab13ec9ed97b to your computer and use it in GitHub Desktop.
Save tatey/6354af3aeacd00e8c488ab13ec9ed97b to your computer and use it in GitHub Desktop.
Federal Election 2019 Bingo Card Generator in Ruby
$ ruby 01_bingo.rb > ~/Downloads/board_1.html
require "erb"
class Cell < Struct.new(:seat, :party, :margin, :trivia)
end
class Board
def initialize(cells)
@rows = cells.shuffle[0..8].each_with_index.reduce([]) do |rows, (cell, index)|
cols = (rows[index % 3] ||= [])
cols << cell
rows
end
end
def generate
ERB.new(<<-HTML
<!DOCTYPE html>
<html>
<head>
<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;
}
</style>
</head>
<body>
<h1>Election Party 2019 🎉</h1>
<table>
<% @rows.each do |cols| %>
<tr>
<% cols.each do |col| %>
<td class="party party-<%= col.party.downcase %>">
<span class="title"><%= col.seat %></span>
<span class="subtitle"><%= col.party %> <%= col.margin %></span>
<span class="body"><%= col.trivia %></span>
</td>
<% end %>
<% end %>
</tr>
</table>
</body>
</html>
HTML
).result(binding)
end
end
board = Board.new([
Cell.new("Herbert", "ALP", "0.03%", "Cathy O'Toole was declared the winner by 37 votes"),
Cell.new("Indi", "IND", "5.5%", "Kathy McGowan and the 'Voices for Indi' group are backing new candidate Dr Helen Haines"),
Cell.new("Dawson", "LNP", "3.4%", "George Christensen AKA the MP for Manila"),
Cell.new("Dickson", "LNP", "1.7%", "Ali France VS Peter Dutton"),
Cell.new("Warringah", "LNP", "11.7%", "Staggall VS Tony Abbott"),
Cell.new("Wentworth", "IND", "1.0%", "Independent Dr Kerryn Phelps at the by-election following the resignation of Malcolm Turnbull"),
Cell.new("Cowper", "NAT", "4.6%", "Oakeshott's shot against retiring MP"),
Cell.new("Sturt", "LNP", "5.4%", "Chris Pyne is retiring"),
Cell.new("Pearce", "LNP", "3.6", "Attorney-General Christian Porter had a big swing against him in the last election"),
Cell.new("Higgans", "LNP", "7.4%", "The retiring Liberal MP is Kelly O'Dwyer. Minister for Jobs, Industrial Relations and Women."),
Cell.new("Kooyong", "LNP", "12.8%", "Treasurer Josh Frydenburg VS Julian Burnside QC"),
Cell.new("Hasluck", "LNP", "2.1%", "Aged Care Minister Ken Wyatt faces a tough contest"),
Cell.new("Canning", "LNP", "6.8%", "A very bad result would also put Andrew Hastie at risk"),
Cell.new("Eden-Monaro", "ALP", "2.9%", "Bellweather"),
Cell.new("Lindsay", "ALP", "1.1%", "Bellweather"),
Cell.new("Macquarie", "ALP", "2.2%", "Bellweather"),
Cell.new("Bass", "ALP", "5.4%", "Always votes out the incumbent"),
Cell.new("Longman", "ALP", "0.8%", "Susan Lamb retained this seat in the Super Saturday by-elections"),
Cell.new("Corangamite", "ALP", "0.03%", "$26,500 per person worth of pork barrelling by the LNP"),
Cell.new("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