Module: Rails::Command::Spellchecker

Defined in:
railties/lib/rails/command/spellchecker.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.suggest(word, from:) ⇒ Object



7
8
9
10
11
12
13
# File 'railties/lib/rails/command/spellchecker.rb', line 7

def suggest(word, from:)
  if defined?(DidYouMean::SpellChecker)
    DidYouMean::SpellChecker.new(dictionary: from.map(&:to_s)).correct(word).first
  else
    from.sort_by { |w| levenshtein_distance(word, w) }.first
  end
end