Class: ChatCorrect::Spelling
- Inherits:
-
Object
- Object
- ChatCorrect::Spelling
- 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
-
#token_a ⇒ Object
readonly
Returns the value of attribute token_a.
-
#token_b ⇒ Object
readonly
Returns the value of attribute token_b.
Instance Method Summary collapse
-
#initialize(token_a:, token_b:) ⇒ Spelling
constructor
A new instance of Spelling.
- #spelling_error? ⇒ Boolean
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_a ⇒ Object (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_b ⇒ Object (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
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 |