Skip to content
Browse files

Teams for lunetas

  • Loading branch information...
1 parent da955c6 commit b5e714010a525a5295eea4aaf3ea6930eefe3ffc @ivanvc committed Aug 23, 2010
Showing with 37 additions and 16 deletions.
  1. +8 −5 config.ru
  2. +29 −11 team-names.rb
View
13 config.ru
@@ -1,7 +1,10 @@
-require 'rubygems'
-require 'bundler'
-Bundler.setup
-require 'app'
+#require 'rubygems'
+#require 'bundler'
+#Bundler.setup
+#require 'app'
+#
+#run Sinatra::Application
-run Sinatra::Application
+require 'team-names'
+run Lunetas::Bag
View
40 team-names.rb
@@ -1,18 +1,36 @@
require 'rubygems'
require 'yaml'
+require 'lunetas'
-def create_names(quantity, nouns = [], adjectives = [])
- names = []
- quantity.times do
- names << "#{nouns.delete(nouns.choice)} #{adjectives.choice}"
+class TeamNames
+ include Lunetas::Candy
+ matches '^/index.html'
+
+ def before
+ @@yaml ||= YAML::load(File.read 'team-names.yml')
+ @@teams ||= {}
+ @nouns = @@yaml['names']['nouns']
+ @adjectives = @@yaml['names']['adjectives']
+ @players = @@yaml['names']['players']
+ end
+
+ def get
+ team, players = create_name
+ html = ['<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"><center>']
+ html << ["<h1>#{team}</h1><h2>#{players.join('</h2><h2>')}</h2>"] if team
+ html << @@teams.map { |team, players| "<p>#{team}: #{players.join(', ')}</p>" }
+ html << '<input type="button" value="Next Team" onClick="window.location.reload()">'
+ html << "</center>"
+ html
end
- names
-end
-source = YAML::load(File.read ARGV[0])
-puts source.inspect
-available_nouns = source["names"]["nouns"]
-available_adjvs = source["names"]["adjectives"]
+ def create_name
+ return if @players.empty?
+ team_name = "#{@nouns.delete(@nouns.choice)} #{@adjectives.delete @adjectives.choice}"
+ @@teams[team_name] = []
+ 2.times { @@teams[team_name] << @players.delete(@players.choice) }
+ [team_name, @@teams[team_name]]
+ end
-puts create_names(ARGV[1].to_i, available_nouns, available_adjvs)
+end

0 comments on commit b5e7140

Please sign in to comment.
Something went wrong with that request. Please try again.