Class: ChatCorrect::Spelling

Inherits:
Object
  • Object
show all
Defined in:
lib/chat_correct/spelling.rb

Constant Summary collapse

WORD_CHOICE =
["the", "that", "this", "on", "at", "in", "an", "it", "if", "of", "to"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token_a:, token_b:) ⇒ Spelling

Returns a new instance of Spelling.



5
6
7
8
# File 'lib/chat_correct/spelling.rb', line 5

def initialize(token_a:, token_b:)
  @token_a = token_a
  @token_b = token_b
end

Instance Attribute Details

#token_aObject (readonly)

Returns the value of attribute token_a.



4
5
6
# File 'lib/chat_correct/spelling.rb', line 4

def token_a
  @token_a
end

#token_bObject (readonly)

Returns the value of attribute token_b.



4
5
6
# File 'lib/chat_correct/spelling.rb', line 4

def token_b
  @token_b
end

Instance Method Details

#spelling_error?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# 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