This method takes a string and parses the syllables. I've broken much of the logic into helper methods. Without getting into the helper methods, it's pretty easy to tell what this is doing. But there are a lot of conditionals. I tried handling the conditions that handle adding to the syllables
variable and those that subtract as two separate methods, but syllables
kept changing value out from under me.
def count_syllables
exceptions = YAML::load_file(File.join(__dir__, 'exceptions.yml'))['exceptions']
return exceptions[word.to_s] if exceptions.keys.include?(word)
syllables = count_vowels
syllables += count_ys_in_vowel_role if contains_non_initial_y?
syllables += 1 if contains_le_vowel_sound?
syllables += 1 if begins_with_re_vowel?
syllables += 1 if ends_in_sm?
syllables -= 1 if ends_in_silent_e?
syllables -= count_diphthongs if contains_diphthongs?
syllables <= 1 ? 1 : syllables
end