forked from AdaGold/portmanteau-generator
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ports - Kim Fasbender #26
Open
Kimberly-Fasbender
wants to merge
3
commits into
Ada-C11:master
Choose a base branch
from
Kimberly-Fasbender:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# program that generates a portmanteau by combining two words that the | ||
# user enters | ||
|
||
# outputs welcome message | ||
puts "\nWelcome to Portmanteau Pro Deluxe 5!" | ||
print "I will combine any two words, of your choice, into one AMAZING " | ||
puts "new word!" | ||
|
||
# method that checks whether a letter is a vowel or not | ||
def is_vowel?(letter) | ||
if ["a", "e", "i", "o", "u"].include?(letter) | ||
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
# method that returns user input after verifying that is at least 2 | ||
# letters in length | ||
def input | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work breaking user input into a a separate reusable method. |
||
word = gets.chomp.downcase | ||
until word.length >= 2 | ||
print "ERROR! Please enter a word that is at least 2 letters in " | ||
print "length: " | ||
word = gets.chomp.downcase | ||
end | ||
return word | ||
end | ||
|
||
# method that returns the first half of the portmanteau | ||
def portmanteau_first_half(word) | ||
last_vowel_index = nil | ||
word.each_char do |letter| | ||
last_vowel_index = word.rindex(letter) if is_vowel?(letter) | ||
end | ||
|
||
if last_vowel_index == nil | ||
return word | ||
else | ||
return word[0...last_vowel_index] | ||
end | ||
end | ||
|
||
# method that returns the second half of the portmanteau | ||
def portmanteau_second_half(word) | ||
first_vowel_index = nil | ||
word.each_char do |letter| | ||
first_vowel_index = word.index(letter) if is_vowel?(letter) | ||
end | ||
|
||
if first_vowel_index == nil | ||
return word | ||
else | ||
return word[first_vowel_index..-1] | ||
end | ||
end | ||
|
||
# method that generates a portmanteau based off input from the user | ||
def run_generator | ||
|
||
# prompts user for two words that they would like to combine | ||
print "\nPlease enter in the first word you would like to combine: " | ||
first_word = input | ||
print "Please enter in the second word you wouldl like to combine: " | ||
second_word = input | ||
|
||
# combines user input and outputs the portmanteau | ||
portmanteau = portmanteau_first_half(first_word) << portmanteau_second_half(second_word) | ||
puts "\n#{first_word} + #{second_word} = #{portmanteau}" | ||
puts "Isn't that an AMAZING new word?!" | ||
end | ||
|
||
# prompts a user on whether they would like to create another | ||
# portmanteau | ||
|
||
# method that checks if an input is yes or no | ||
def yes_no? | ||
input = gets.chomp.downcase | ||
until input == "no" || input == "yes" | ||
print "ERROR! Please enter either yes, or no: " | ||
input = gets.chomp.downcase | ||
end | ||
return input | ||
end | ||
|
||
# prompts a user on whether they would like to create another | ||
# portmanteau | ||
continue = "yes" | ||
while continue == "yes" | ||
run_generator | ||
print "\nWould you like to create another portmanteau (yes/no)? " | ||
continue = yes_no? | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
.include?
returns true or false you could simplify this with: