madlib_lynn 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/looneytune_madlib.txt +1 -0
- data/lib/madlib_lynn_gem.rb +112 -0
- data/lib/penguin_madlib.txt +9 -0
- data/lib/space_madlib.txt +1 -0
- data/lib/test_madlib.txt +2 -0
- metadata +50 -0
@@ -0,0 +1 @@
|
|
1
|
+
Using a/an @@@Noun tied to his tail, Sylvester pulled himself up to Tweety's birdcage and @@@VerbPastTense inside. Sylvester @@@Adverb opened the cage as Tweeted started to shout, "@@@SillyWord!" Not wanting to be caught by Granny, Sylvester @@@Adverb hid Tweety inside a glass jar, holding it shut with his @@@Noun. The jar was soundproof and, although Tweety was @@@Verb up and down and @@@Verb a drum, he couldn't be heard. Then Tweety pulled out a pin, smiling at Sylvester who had begin to sweat, and poked him in his nose so he could escape. Sylvester @@@Adverb released Tweety, who started yelling again. Afraid of Granny, Sylvester hurried back to the floor and pretended to be alseep. Granny heard Tweety and came into the room with a/an @@@Noun and started hitting Sylvester over the head with it. Then she tossed Sylvester out in the snow. All he could do was complain @@@Adverb to himself, "Sufferin' Succotash!"
|
@@ -0,0 +1,112 @@
|
|
1
|
+
#
|
2
|
+
# MadLib class
|
3
|
+
#
|
4
|
+
# Author:: Lynn Conway
|
5
|
+
#
|
6
|
+
# MadLib class implements the MadLib class. The user chooses the
|
7
|
+
# type of MadLib to play and then enters the different types of
|
8
|
+
# words prompted for. When all words have been entered, the
|
9
|
+
# Mad Lib text is printed out using the words prompted for.
|
10
|
+
#
|
11
|
+
class MadLib
|
12
|
+
#
|
13
|
+
# MadLib types are specified in an array. Prompt the user for the
|
14
|
+
# the type of MadLib game to play.
|
15
|
+
#
|
16
|
+
# @story is a string which contains the finished MadLib. Initialize
|
17
|
+
# to the empty string.
|
18
|
+
# @word_array is an array of hashes. Each hash will hold
|
19
|
+
# a type of word (verb, noun, etc.) and the word the user
|
20
|
+
# enters. Initialize to empty array.
|
21
|
+
#
|
22
|
+
def initialize
|
23
|
+
@story = ""
|
24
|
+
@word_array = []
|
25
|
+
@madlib_types = ["LooneyTune", "Space", "Penguin"]
|
26
|
+
puts "Which MadLib would you like to play?"
|
27
|
+
n = @madlib_types.length
|
28
|
+
for i in 0...(n-1)
|
29
|
+
print @madlib_types[i] + " or "
|
30
|
+
end
|
31
|
+
print @madlib_types[n-1] + "? "
|
32
|
+
end
|
33
|
+
#
|
34
|
+
# Read in the type of MadLib game the user wants to play and save
|
35
|
+
# the string in the variable @madlib.
|
36
|
+
#
|
37
|
+
def get_madlib_type
|
38
|
+
@madlib = gets.chomp
|
39
|
+
end
|
40
|
+
#
|
41
|
+
# Read in the MadLib text from the appropriate text file and save each
|
42
|
+
# each line in @story_array. Also, save them as one string in @story.
|
43
|
+
#
|
44
|
+
def read_madlib
|
45
|
+
@story_array = IO.readlines("#{@madlib}_madlib.txt")
|
46
|
+
@story_array.each do |line|
|
47
|
+
@story += line
|
48
|
+
end
|
49
|
+
end
|
50
|
+
#
|
51
|
+
# The text contains words starting with '@@@'. These are the words
|
52
|
+
# that are going to be replaced in the text. They are stored in an array
|
53
|
+
# of hashes, @word_array, as the keys.
|
54
|
+
#
|
55
|
+
def collect_word_types
|
56
|
+
@story_array.each do |line|
|
57
|
+
this_line = line.split
|
58
|
+
this_line.each do |word|
|
59
|
+
if word =~ /@@@/
|
60
|
+
word.sub!(/@@@/, "").sub!(/\W/, "")
|
61
|
+
@word_array.push({word => ""})
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
#
|
67
|
+
# The user is prompted for a particular type of word for the
|
68
|
+
# program to use as a replacement word. They are stored the array
|
69
|
+
# of hashes, @word_array, as the values.
|
70
|
+
#
|
71
|
+
def user_input
|
72
|
+
@word_array.each do |h|
|
73
|
+
h.each_key do |key|
|
74
|
+
print "Enter a #{key}: "
|
75
|
+
v = gets.chomp
|
76
|
+
h[key] = v
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
#
|
82
|
+
# Use the hashes to find the words in the text (hash keys) and replace
|
83
|
+
# them with the user's chosen words (hash values) in the @story string.
|
84
|
+
# Print out @story string.
|
85
|
+
#
|
86
|
+
def print_madlib
|
87
|
+
@word_array.each do |h|
|
88
|
+
h.each do |key, value|
|
89
|
+
@word = "@@@" << key
|
90
|
+
@story.sub!(/#{Regexp.quote(@word)}/, value)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
puts @story
|
94
|
+
end
|
95
|
+
#
|
96
|
+
# Method to play the MadLib game.
|
97
|
+
#
|
98
|
+
def play
|
99
|
+
self.get_madlib_type
|
100
|
+
self.read_madlib
|
101
|
+
self.collect_word_types
|
102
|
+
self.user_input
|
103
|
+
self.print_madlib
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Create MadLib class and play the game
|
110
|
+
#
|
111
|
+
madlib = MadLib.new
|
112
|
+
madlib.play
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Fellow bird @@@Noun, we are honored to have as our speaker today Dr. @@@PersonsLastName, America's foremost @@@Noun on penguins and other cold-climate @@@NounPlural. The doctor has @@@Adverb agreed to answer three questions before we @@@Verb for lunch.
|
2
|
+
|
3
|
+
Doctor: First question, please.
|
4
|
+
Question: Why do penguins walk in such a/an @@@Adjective way?
|
5
|
+
Doctor: You'd walk funny too if every step you took put your @@@BodyPart on frozen @@@NounPlural. Next!
|
6
|
+
Question: How do penguins manage to @@@Verb in such a cold @@@Noun?
|
7
|
+
Doctor: They have an abundance of @@@Noun under their @@@BodyPart. This fat insulates them against @@@Adjective weather. Next!
|
8
|
+
Question: Why do we only see black and white penguins?
|
9
|
+
Doctor: Because they're very formal @@@NounPlural. They dress for all occasions, especially sit-down @@@Noun.
|
@@ -0,0 +1 @@
|
|
1
|
+
In 1981, the U.S. launched the first real Space @@@Noun. It was named Columbia and was piloted by two brave @@@NounPlural. They had practiced @@@VerbEndingInIng for two years and were expert @@@NounPlural. Columbia took off from @@@City using its powerful first-stage @@@NounPlural and soared off into the @@@Adverb blue @@@Noun. At an altitude of @@@Number feet, it went into orbit around the @@@Noun. For people watching from Earth it was a/an @@@Adverb sight to @@@Verb! Who could really @@@Verb that there were two @@@NounPlural in space? It was mind @@@VerbEndingInIng. After 3 orbits, the shuttle landed @@@Adverb at an air force @@@Noun. It was a/an @@@Adjective day for the U.S. Space Program.
|
data/lib/test_madlib.txt
ADDED
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: madlib_lynn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lynn Conway
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-10 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Lynn's implementation of the MadLib game
|
15
|
+
email: lconway@bendbroadband.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/madlib_lynn_gem.rb
|
21
|
+
- lib/test_madlib.txt
|
22
|
+
- lib/penguin_madlib.txt
|
23
|
+
- lib/space_madlib.txt
|
24
|
+
- lib/looneytune_madlib.txt
|
25
|
+
homepage: http://rubygems.org/gems/lynn_madlib_gem
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 1.8.24
|
47
|
+
signing_key:
|
48
|
+
specification_version: 3
|
49
|
+
summary: Lynn's MadLib game
|
50
|
+
test_files: []
|