class ChatCorrect::Spelling

Constants

WORD_CHOICE

Attributes

token_a[R]
token_b[R]

Public Class Methods

new(token_a:, token_b:) click to toggle source
# File lib/chat_correct/spelling.rb, line 5
def initialize(token_a:, token_b:)
  @token_a = token_a
  @token_b = token_b
end

Public Instance Methods

spelling_error?() click to toggle source
# File lib/chat_correct/spelling.rb, line 10
def spelling_error?
  token_a.length > 1 && token_b.length > 1 &&
  token_a.gsub(/[[:punct:]]/, "") != "" && token_b.gsub(/[[:punct:]]/, "") != "" &&
  !(token_a[0] != token_b[0] && Text::Levenshtein.distance(token_a.downcase, token_b.downcase) > 1) &&
  !(WORD_CHOICE.include?(token_a.downcase) && WORD_CHOICE.include?(token_b.downcase)) &&
  Text::Levenshtein.distance(token_a.downcase, token_b.downcase) < 3 && token_a.downcase != token_b.downcase
end