Created
September 8, 2010 01:08
-
-
Save ashaw/569421 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'erb' | |
class GawkerBingo | |
def initialize | |
@bingo_items = [] | |
File.open('gawkerbingo.txt', 'r').each do |line| | |
@bingo_items << line.chomp | |
end | |
end | |
def randomize | |
chosen_items = [] | |
until chosen_items.size == 14 | |
chosen_item = @bingo_items.at(rand(@bingo_items.size)) | |
unless chosen_items.include?(chosen_item) | |
chosen_items << chosen_item | |
end | |
end | |
template = ERB.new <<-HTML | |
<div class="bingo_container"> | |
<table border="1"> | |
<tr> | |
<% chosen_items.each_with_index do |item,idx| %> | |
<td><%= item %></td> | |
<% if [4,8,14].include?(idx) %> | |
</tr><tr> | |
<% elsif idx == 6 %> | |
<td class='bingo'>BINGO</td> | |
<% end %> | |
<% end %> | |
</tr> | |
</table> | |
</div> | |
HTML | |
template.result(binding) | |
end | |
end | |
class CreateCards | |
STYLE = <<CSS | |
<style> | |
.bingo_container { page-break-after:always; height: 11in; text-align:center; } | |
table { width: 8in; height: 11in; border: .01in solid #000; } | |
table tr td { padding: .45in; text-align:center; font-family:Helvetica,arial,sans-serif;font-weight:bold; font-size: 14pt; width:2in; } | |
table tr td.bingo { background-color: #000; color:#fff; } | |
</style> | |
CSS | |
def initialize(pages) | |
@pages = pages | |
f = File.open('gawker_bingo_cards.html', 'w+') | |
f << STYLE | |
g = GawkerBingo.new | |
(0..(@pages - 1)).each do |page| | |
p = g.randomize | |
f << p | |
end | |
f.close | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nicely done, sir!