# -*- ruby -*-
#
# Shakespearean insult generator
#
# Copyright (c) 2006 Stephen Williams, all rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the copyright holder may not be used to endorse or
# promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
### BEGIN class definition
class Shakespeare
### BEGIN class constants
RCSID = "$Id: shakespeare_rbx.txt,v 1.2 2006/07/22 16:56:37 stephen Exp $"
# From http://www.ljhs.sandi.net/faculty/mteachworth/strange-n-mundane/interesting-articles/shakespearean-insults.htm
DATA =
[
"artless base-court apple-john",
"bawdy bat-fowling baggage",
"beslubbering beef-witted barnacle",
"bootless beetle-headed bladder",
"churlish boil-brained boar-pig",
"cockered clapper-clawed bugbear",
"clouted clay-brained bum-bailey",
"craven common-kissing canker-blossom",
"currish crook-pated clack-dish",
"dankish dismal-dreaming clotpole",
"dissembling dizzy-eyed coxcomb",
"droning doghearted codpiece",
"errant dread-bolted death-token",
"fawning earth-vexing dewberry",
"fobbing elf-skinned flap-dragon",
"froward fat-kidneyed flax-wench",
"frothy fen-sucked flirt-gill",
"gleeking flap-mouthed foot-licker",
"goatish fly-bitten fustilarian",
"gorbellied folly-fallen giglet",
"impertinent fool-born gudgeon",
"infectious full-gorged haggard",
"jarring guts-griping harpy",
"loggerheaded half-faced hedge-pig",
"lumpish hasty-witted horn-beast",
"mammering hedge-born hugger-mugger",
"mangled hell-hated jolthead",
"mewling idle-headed lewdster",
"paunchy ill-breeding lout",
"pribbling ill-nurtured maggot-pie",
"puking knotty-pated malt-worm",
"puny milk-livered mammet",
"quailing motley-minded measle",
"rank onion-eyed minnow",
"reeky plume-plucked miscreant",
"roguish pottle-deep moldwarp",
"ruttish pox-marked mumble-news",
"saucy reeling-ripe nut-hook",
"spleeny rough-hewn pigeon-egg",
"spongy rude-growing pignut",
"surly rump-fed puttock",
"tottering shard-borne pumpion",
"unmuzzled sheep-biting ratsbane",
"vain spur-galled scut",
"venomed swag-bellied skainsmate",
"villainous tardy-gaited strumpet",
"warped tickle-brained varlot",
"wayward toad-spotted vassal",
"weedy unchin-snouted whey-face",
"yeasty weather-bitten wagtail"
]
EXTRACT = /^(\S+)\s+(\S+)\s+(\S+)$/
RCS_MANGLE = /^(.+)(shakespeare\.rbx)(.+)$/
STARTS_WITH_VOWEL = /^[aeiou]/
### END class constants
### BEGIN constructor
def initialize
@cgi = CGI.new
end
### END constructor
### BEGIN private methods
private
# Mangle RCSID string to include linked filename
def rcs_mangle
rcsmatch = RCS_MANGLE.match(RCSID)
if rcsmatch
filename = rcsmatch[2]
filename2 = filename.tr('.', '_') + '.txt'
"#{rcsmatch[1]}#{filename}#{rcsmatch[3]}"
else
RCSID
end
end
### END private methods
### BEGIN public methods
public
# Chooses two adjectives and a noun from the data
def pick_words
@adjective1 = EXTRACT.match(DATA[rand(DATA.size)])[1]
@adjective2 = EXTRACT.match(DATA[rand(DATA.size)])[2]
@noun = EXTRACT.match(DATA[rand(DATA.size)])[3]
@adjective1, @adjective2 = @adjective2, @adjective1 if rand(2) == 0
@article = STARTS_WITH_VOWEL.match(@adjective1) ? "an" : "a"
end
# Generates and displays the HTML
def output
@cgi.out("status" => "200 Forsooth!") do
<Forsooth!
#{rcs_mangle}
END
end
end
### END public methods
end
### END class definition
shakespeare = Shakespeare.new
shakespeare.pick_words
shakespeare.output