From 2581f516be825c0819d24249b0992a4a79f10b6d Mon Sep 17 00:00:00 2001 From: Sarah Scotton <36459143+sjscotton@users.noreply.github.com> Date: Fri, 8 Feb 2019 10:21:35 -0800 Subject: [PATCH 1/2] Create generator.rb --- generator.rb | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 generator.rb diff --git a/generator.rb b/generator.rb new file mode 100644 index 0000000..a3d1474 --- /dev/null +++ b/generator.rb @@ -0,0 +1,76 @@ +def is_vowel?(letter) + vowels = ["a", "e", "i", "o", "u"] + if vowels.include?(letter.downcase) + return true + end + return false +end + +def get_word_from_user(word) + puts "What is the #{word} to combine?" + word = gets.chomp.to_s + while word.length < 2 || word.include?(" ") + puts "Word must be at least 2 characters long, and must not contain any spaces." + word = gets.chomp.to_s + end + return word +end + +def chop_first_word(first_word) + stop_index = first_word.length - 1 + + first_word.reverse.each_char do |letter| + if is_vowel?(letter) + break + elsif stop_index == 0 + stop_index = first_word.length + break + end + stop_index = stop_index - 1 + end + + first_half = first_word[0...stop_index] + return first_half +end + +def chop_second_word(second_word) + start_index = 0 + + second_word.each_char do |letter| + if is_vowel?(letter) + break + elsif start_index == second_word.length - 1 + start_index = 0 + break + end + start_index += 1 + end + second_half = second_word[start_index..second_word.length] + return second_half +end + +def run_generator + first_word = get_word_from_user("first word") + second_word = get_word_from_user("second word") + + first_half = chop_first_word(first_word) + second_half = chop_second_word(second_word) + + new_word = first_half + second_half + + puts "#{first_word} + #{second_word} is #{new_word}" +end + +run_generator +play_again = true + +while play_again + puts "Wasn't that fun? if you would like to try again, please enter 'yes'." + responce = gets.chomp.to_s + if responce == "yes" + run_generator + else + play_again = false + end +end + From 165d8e1a1c415ac9f373d732fbd6a5efd28ec160 Mon Sep 17 00:00:00 2001 From: Sarah Scotton <36459143+sjscotton@users.noreply.github.com> Date: Sat, 9 Feb 2019 14:38:50 -0800 Subject: [PATCH 2/2] Update generator.rb --- generator.rb | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/generator.rb b/generator.rb index a3d1474..0173aed 100644 --- a/generator.rb +++ b/generator.rb @@ -6,6 +6,7 @@ def is_vowel?(letter) return false end + def get_word_from_user(word) puts "What is the #{word} to combine?" word = gets.chomp.to_s @@ -16,39 +17,35 @@ def get_word_from_user(word) return word end + def chop_first_word(first_word) stop_index = first_word.length - 1 first_word.reverse.each_char do |letter| if is_vowel?(letter) - break - elsif stop_index == 0 - stop_index = first_word.length - break + return first_word[0...stop_index] end - stop_index = stop_index - 1 + stop_index -= 1 end - - first_half = first_word[0...stop_index] - return first_half + stop_index = first_word.length + return first_word[0...stop_index] end + def chop_second_word(second_word) start_index = 0 second_word.each_char do |letter| if is_vowel?(letter) - break - elsif start_index == second_word.length - 1 - start_index = 0 - break + return second_word[start_index..second_word.length] end start_index += 1 end - second_half = second_word[start_index..second_word.length] - return second_half + start_index = 0 + return second_word[start_index..second_word.length] end + def run_generator first_word = get_word_from_user("first word") second_word = get_word_from_user("second word") @@ -61,6 +58,7 @@ def run_generator puts "#{first_word} + #{second_word} is #{new_word}" end + run_generator play_again = true @@ -73,4 +71,3 @@ def run_generator play_again = false end end -