Skip to content

Instantly share code, notes, and snippets.

@cantlin
Created August 7, 2011 21:14
Show Gist options
  • Save cantlin/1130801 to your computer and use it in GitHub Desktop.
Save cantlin/1130801 to your computer and use it in GitHub Desktop.
class Suggester
class << self
def variants_for word
[word.downcase, word.capitalize, word.squeeze]
end
def suggestions_for word
suggestions = self.vowel_suggestions_for word
suggestion_variants = []
suggestions.each do |suggestion|
variants = self.variants_for suggestion
variants.each do |variant|
unless suggestions.include? variant
suggestion_variants << variant
end
end
end
suggestions + suggestion_variants
end
def vowel_suggestions_for word
vowels = ['a', 'e', 'i', 'o', 'u']
suggestions = [word]
word.chars.each_with_index do |char, index|
next unless vowels.include? char.downcase
vowels.each do |vowel|
suggestions.each do |suggestion|
suggestion[index] = vowel
unless suggestions.include? suggestion
suggestions << suggestion
end
end
end
end
suggestions
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment