123456789_123456789_123456789_123456789_123456789_

Class: DidYouMean::CorrectElement

Relationships & Source Files
Inherits: Object
Defined in: lib/did_you_mean/tree_spell_checker.rb

Overview

identifies the elements close to element

Class Method Summary

Instance Method Summary

Constructor Details

.newCorrectElement

[ GitHub ]

  
# File 'lib/did_you_mean/tree_spell_checker.rb', line 117

def initialize
end

Instance Method Details

#call(names, element)

[ GitHub ]

  
# File 'lib/did_you_mean/tree_spell_checker.rb', line 120

def call(names, element)
  return names if names.size == 1
  str = normalize element
  return [str] if names.include? str
  checker = ::DidYouMean::SpellChecker.new(dictionary: names)
  checker.correct(str)
end

#normalize(leaf) (private)

[ GitHub ]

  
# File 'lib/did_you_mean/tree_spell_checker.rb', line 130

def normalize(leaf)
  str = leaf.dup
  str.downcase!
  return str unless str.include? '@'
  str.tr!('@', '  ')
end