Class: AlfonsoX::SpellChecker::Dictionary::WordListFile
- Inherits:
-
Object
- Object
- AlfonsoX::SpellChecker::Dictionary::WordListFile
- Defined in:
- lib/alfonsox/spellchecker/dictionary/word_list_file.rb
Overview
Custom dictionary loader composed by a word list from a file
Instance Attribute Summary collapse
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Class Method Summary collapse
-
.from_config(yml_config) ⇒ Object
Load from Yml.
Instance Method Summary collapse
-
#initialize(word_list_file_path) ⇒ WordListFile
constructor
Initialize a AlfonsoX::SpellChecker::Dictionary::WordListFile from a file path.
-
#word_present?(word) ⇒ Boolean
Inform if a word is present in this dictionary.
Constructor Details
#initialize(word_list_file_path) ⇒ WordListFile
Initialize a AlfonsoX::SpellChecker::Dictionary::WordListFile from a file path. Note the words must be in different lines.
16 17 18 19 |
# File 'lib/alfonsox/spellchecker/dictionary/word_list_file.rb', line 16 def initialize(word_list_file_path) word_list = ::File.readlines(word_list_file_path).map(&:chomp) @words = word_list.map(&:downcase) end |
Instance Attribute Details
#words ⇒ Object (readonly)
Returns the value of attribute words.
11 12 13 |
# File 'lib/alfonsox/spellchecker/dictionary/word_list_file.rb', line 11 def words @words end |
Class Method Details
.from_config(yml_config) ⇒ Object
Load from Yml
22 23 24 |
# File 'lib/alfonsox/spellchecker/dictionary/word_list_file.rb', line 22 def self.from_config(yml_config) new(yml_config['path']) end |
Instance Method Details
#word_present?(word) ⇒ Boolean
Inform if a word is present in this dictionary.
27 28 29 |
# File 'lib/alfonsox/spellchecker/dictionary/word_list_file.rb', line 27 def word_present?(word) @words.include?(word.downcase) end |