Class: AlfonsoX::SpellChecker::File
- Inherits:
-
Object
- Object
- AlfonsoX::SpellChecker::File
- Defined in:
- lib/alfonsox/spellchecker/file.rb
Overview
Each one of the source code files we want to spell-check
Instance Attribute Summary collapse
-
#incorrect_words ⇒ Object
readonly
Returns the value of attribute incorrect_words.
Class Method Summary collapse
-
.word_splitter(word_line) ⇒ Array<String>
Tokenize a line, i.e.
Instance Method Summary collapse
-
#initialize(file_path, dictionaries) ⇒ File
constructor
Initialize spellcheck on a file with some dictionaries.
-
#spellcheck ⇒ Object
Perform the spellcheck on the file.
Constructor Details
#initialize(file_path, dictionaries) ⇒ File
Initialize spellcheck on a file with some dictionaries
16 17 18 19 20 |
# File 'lib/alfonsox/spellchecker/file.rb', line 16 def initialize(file_path, dictionaries) @file_path = file_path @dictionaries = dictionaries @incorrect_words = [] end |
Instance Attribute Details
#incorrect_words ⇒ Object (readonly)
Returns the value of attribute incorrect_words.
10 11 12 |
# File 'lib/alfonsox/spellchecker/file.rb', line 10 def incorrect_words @incorrect_words end |
Class Method Details
.word_splitter(word_line) ⇒ Array<String>
Tokenize a line, i.e. split words of a line.
34 35 36 |
# File 'lib/alfonsox/spellchecker/file.rb', line 34 def self.word_splitter(word_line) word_line.split(/[_\-\s\d]+|(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|\W+/).map(&:downcase) end |
Instance Method Details
#spellcheck ⇒ Object
Perform the spellcheck on the file
23 24 25 26 27 28 29 |
# File 'lib/alfonsox/spellchecker/file.rb', line 23 def spellcheck lines = ::File.open(@file_path).readlines lines.each_with_index do |line, line_index| check_line(line, line_index + 1) end @incorrect_words end |