forked from Ada-C11/portmanteau-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.rb
57 lines (51 loc) · 1.61 KB
/
generator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def is_vowel?(letter)
if "aeiou".include?(letter)
return true
else
return false
end
end
# 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.
def run_generator
# Get words to combine from user
print "What is the first word to combine? "
word_a = gets.chomp.downcase
until word_a.length >= 2
puts "Word must be greater than 1 character! Try again: "
word_a = gets.chomp.downcase
end
# Truncate word_a: all letters UNTIL and EXCLUDING the last vowel
# Check for vowels
word_a.reverse!
new_word_a = ""
word_a.each_char.with_index do |letter, index|
if is_vowel?(letter) == true
new_word_a = "#{word_a[(index + 1)..-1]}"
new_word_a = new_word_a.reverse!
break
else
new_word_a = word_a.reverse!
end
end
# Get second word
print "What is the second word to combine? "
word_b = gets.chomp.downcase
until word_b.length >= 2
puts "Word must be greater than 1 character! Try again: "
word_b = gets.chomp.downcase
end
# Truncate word_b: all letters AFTER and INCLUDING first vowel
# Check for vowels
new_word_b = ""
word_b.each_char.with_index do |letter, index|
if is_vowel?(letter) == true
new_word_b = "#{word_b[(index + 1)..-1]}"
else
new_word_b = word_b
end
end
portmanteau = "#{new_word_a}#{new_word_b}"
puts "Your new word is #{portmanteau.upcase}. Cool, huh!?"
end
puts "Hello, welcome to my wild portmanteau generator!"
run_generator