I am trying to ask the user for a name so we can create a fake name.
Fake name will:
Swap the first and last name
Change all the vowels (a,e,i,o,u) to next vowel, So 'a' would become 'e','u' would become 'a'
Change all the consonants to (besides the vowels) to the next consonant in the alphabet, So 'd' would become 'f', 'n' would become 'p'
I am unable to get the first and last name capitalized at the end of the program. Any advice on how to do this?
I am also trying to Use a data structure to store the fake names as they are entered. When the user exits the program, iterate through the data structure and print all of the data the user entered. A sentence like "Vussit Gimodoe is actually Felicia Torres" or "Felicia Torres is also known as Vussit Gimodoe
# ---- Swap First and Last Name ----
def name_swap(name)
name.split.reverse.join(' ')
end
# ---- Change all the vowels ----
def vowel_change(name)
vowels = ['a', 'e', 'i', 'o', 'u']
name = name.downcase.split('')
new_name = name.map do |vow|
if vowels.include?(vow)
vowels.rotate(1)[vowels.index(vow)]
elsif vowels == 'u'
vowels.replace('a')
else
vow
end
end
new_name.join
end
# ---- Change the constant ----
def constant_change(name)
constants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z']
name = name.downcase.split('')
new_name = name.map do |letter|
if constants.include?(letter)
constants.rotate(1)[constants.index(letter)]
elsif constants == 'z'
constants.replace('b')
else
letter
end
end
new_name.join.capitalize!
end
# ---- User Interface and Data Storage----
valid_input = false
agents ={}
user_input = ""
secret_name = ""
until valid_input
puts "Hello Secret Agent, to begin please enter the name you would like to change. When you are finished, type 'quit' !"
user_input = gets.chomp.downcase
if user_input == "quit"
puts "Thank You!"
valid_input = true
else
secret_name = name_swap(vowel_change(constant_change(user_input)))
puts "Your secret name is #{secret_name} "
end
agents[user_input] = secret_name
end
agents.each do |name, scramble|
puts"#{name} is also known #{scramble}"
end
The problem is when I return the final agent name the name is lower case and I need both the first name and last name capitalized. It is also taking quit to exit the until loop as a name.