Class: Leftovers::ConfigLoader::Suggester

Inherits:
Object
  • Object
show all
Defined in:
lib/leftovers/config_loader/suggester.rb

Instance Method Summary collapse

Constructor Details

#initialize(words) ⇒ Suggester

Returns a new instance of Suggester.



6
7
8
9
# File 'lib/leftovers/config_loader/suggester.rb', line 6

def initialize(words)
  @words = words
  @did_you_mean = ::DidYouMean::SpellChecker.new(dictionary: words) if defined?(::DidYouMean)
end

Instance Method Details

#suggest(word) ⇒ Object



11
12
13
14
15
# File 'lib/leftovers/config_loader/suggester.rb', line 11

def suggest(word)
  suggestions = did_you_mean.correct(word) if did_you_mean
  suggestions = words if !suggestions || suggestions.empty?
  suggestions
end