Skip to content

Instantly share code, notes, and snippets.

@ashaw
Created September 8, 2010 01:08
Show Gist options
  • Save ashaw/569421 to your computer and use it in GitHub Desktop.
Save ashaw/569421 to your computer and use it in GitHub Desktop.
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
@nataliepo
Copy link

Is this for tonight's Meetup?

@ashaw
Copy link
Author

ashaw commented Sep 8, 2010

yep!

@jcmuller
Copy link

jcmuller commented Sep 9, 2010

Nicely done, sir!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment