- Individual, stage 1 project
- Due before class, Fri. Feb 8
A portmanteau is "a linguistic blend of words, in which parts of multiple words or their phones (sounds) are combined into a new word." Popular examples of portmanteau in English include:
- smoke and fog combine to create smog
- jeans and shorts combine to create jorts
- breakfast and lunch combine to create brunch
- spoon and fork combine to create spork
- hungry and angry combine to create hangry
- Write Ruby code with statements that practice conditional logic, using
if
,elsif
, andelse
when appropriate - Write Ruby code with statements that practice loops, like
while
anduntil
when appropriate - Write Ruby code that takes in user input using
gets.chomp
- Practice creating, storing, and modifying variables
- Practice creating and using methods
We will build a command line interface (CLI) program that allows any user to interact with the command line to perform simple manipulation of words and create portmanteaus. The program should ask the user to type in and enter in pieces of input. Based on the input that the user typed in, the program should output its evaluation.
The rules we will follow to create a portmanteau in this project are simplified and specific. Making portmanteaus in English is difficult and complex, so please follow the project specifications below closely. As a programmer, there's a balance between challenging assumptions and expectations and doing personal software design, versus fulfilling project requirements. Over time, we will have projects that require more programmer input and design. In this project, we will be asking you lean towards following the given rules.
You should write your program as a series of statements within a file generator.rb
. Anyone with this file should be able to run the command $ ruby generator.rb
to run the program.
When a user runs this program, the program should politely ask the user for the following things:
- a word to combine to begin the portmanteau
- a second word to combine and end the portmanteau
Then, the program should use the two input words in to output and display the result of the following rules and create one portmanteau.
Here is an example of what your program could look like. It is not required to look exactly like this:
In this wave, work on the following features:
- establishing the
run_generator
method - getting all of the input needed
- storing those pieces of input into variables
- being able to print out those variables
- iterating through individual characters in words to check which characters are vowels
Make a method named run_generator
. This method has no parameters. Start this method by outputting a prompt to ask for a first input word A, and accept some input. Then, ask for a second input word B, and accept some input.
Make sure you save these inputs into variables. Then, output these variables by printing them to the console, and the statement "in the run_generator method"
.
Then, call or invoke the run_generator
outside of the method definition, at the bottom of the generator.rb
file.
Confirm that this is all setup by running $ ruby generator.rb
, and make sure you can input two words, and you eventually see the statement "in the run_generator method"
in the console.
Next, make a method named is_vowel?
. This method should:
- take in one argument, a string, which will represent one letter. Name this argument
letter
- return either
true
orfalse
-- true if it is either the lettersa
,e
,i
,o
, oru
, false if it is anything else - be defined above the definition for the
run_generator
method, in the samegenerator.rb
file
Test that this method works by calling it inside of the run_generator
method, and passing in some test cases, and printing the result to the console. Here is an example of what that might look like:
def run_generator
# ... maybe some other code ...
test_vowel = "i"
puts "Is #{test_vowel} a vowel?"
puts is_vowel?(test_vowel)
test_consonant = "g"
puts "Is #{test_consonant} a vowel?"
puts is_vowel?(test_consonant) ...
# ... maybe some other code ...
end
In wave two, work on combining the first two input words using the rules below. They are broken up into the groups "Input validation rules" and "combination rules."
Before you start wave 2, do the following things:
- Read through all of the rules in both groups
- Write down any questions you have
- Talk about the rules with someone around you
- Ask for further clarification, if needed
- Ruby has a great built-in way to iterate through characters in a String using the method named
each_char
. Read through the documentation foreach_char
, and work through some examples inirb
. What does"hello world".each_char {|letter| print "#{letter} :) " }
do? - Make a strategy. Break down the parts. What rules translate into loops? What kind of loops? What rules translate into conditionals? What kinds of conditionals? Don't spend more than 15 minutes on this, moving to the next step is usually more helpful
- Write pseudocode
- Write code!
- The input for the first word must be at least two characters. If the input is less than 2 characters (as in 0 or 1 characters), the program should handle it in the following procedure:
- output a message to the command line that informs the user that the input was invalid and must be at least 2 characters
- asks the user to re-enter the input for the same prompt
- does this until the input is valid
- uses the newer, valid input
- The input for the second word must be at least two characters. Follow the same guidelines as for the first word
There is no requirement that either input must have any specific number vowels or consonants to be valid.
There is no requirement that inputs must be upper or lowercase.
-
Vowels in this program are the following letters:
a
,e
,i
,o
, oru
, and nothing else -
In the first word, find the last instance of a vowel. The first half of the portmanteau will keep every letter of the first word until and excluding its last vowel.
For example, if the first word is
dreams
, thena
is the last vowel in this word. The first part of the new portmanteau isdre
, excluding thea
-
In the second word, find the first instance of a vowel. The second half of the portmanteau will keep every letter of the second word after and including its first vowel.
For example, if the second word is
hopes
, theno
is the first vowel in this word. The second part of the new portmanteau isopes
, including theo
-
If there are no vowels found in the first word, use every letter in the first word in the first part of the portmanteau.
For example, if the first word is
sky
, then there are no vowels to consider. The first part of the new portmanteau issky
-
If there are no vowels in the second word, use every letter in the second word in the second part of the portmanteau.
For example, if the second word is
myth
, then there are no vowels to consider. The second part of the new portmanteau ismyth
Then, combine the two parts. That's all there is to it!
We are ignoring complex rules in this project, because languages are complex! Do not worry about cases such as many vowels in a row, and just rely on the rules outlined above.
Input Word A | Input Word B | Output | Description |
---|---|---|---|
dog | cat | dat | |
cat | dog | cog | |
hungry | angry | hangry | |
jean | shorts | jeorts | |
spoon | fork | spoork | |
breakfast | lunch | breakfunch | |
aa | dog | aog | first is all vowels |
dog | aa | daa | second is all vowels |
xx | dog | xxog | first is all consonants |
dog | xx | dxx | second is all consonants |
aa | xx | axx | first is all vowels, second is all consonants |
xx | aa | xxaa | first is all consonants, second is all vowels |
xx | zz | xxzz | both are all consonants |
aa | ee | aee | both are all vowels |
Edge cases:
Input Word A | Input Word B | Output | Description |
---|---|---|---|
1111 | 2222 | 11112222 | both inputs are digits |
!!!! | @@@@ | !!!!@@@@ | both inputs are symbols |
dog | !!!! | d!!!! | second input is entirely non-letter characters |
!!!! | dog | !!!!og | first input is entirely non-letter characters |
dog | c!a!t | da!t | second input is combination of letter and non-letter characters |
d!o!g | cat | d!at | first input is a combination of letter and non-letter characters |
Any set of inputs/output not covered in this table is not required to implement/or has no specific requirement of how to handle.
Before project submission, test and verify that your program works as expected with the following testing/verification requirements.
To make sure your program works you will need to run your program and check against the following criteria:
- use the example table above
- make sure that it still works regardless of uppercase/lowercase letters
- make sure that the program works as expected if you give 0 or 1 character prompts multiple times in a row
The following is a list of optionals. Should you be ambitious to continue working on this project beyond the requirements, here is a list of features that are interesting. These enhancements are not listed in any particular order; feel free to pick an enhancement from anywhere in the list!
- After running the portmanteau generator, the program should ask if the user wants to continue. The program should accept input, and if the answer is "
yes
", then the program restarts - Gracefully handle user input that does not contain a vowel, so that only words with at least one vowel are accepted. Do so with the following method:
- output a message to the command line that informs the user that the input was invalid
- asks the user to re-enter the input for the same prompt
- does this until the input is valid
- uses the newer, valid input
- There are other ways to iterate through strings letter-by-letter besides using
each_char
. Research other ways to do this, and refactor your code to use one of these ways - Refactor more pieces of code into other helper methods
Please note that you will only be graded on the requirements, and not on the optional enhancements.
Check out the feedback template which lists the items instructors will be looking for as they evaluate your project.