Class: AlfonsoX::SpellChecker::Dictionary::WordListFile

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • word_list_file_path (String)

    Word list file path.



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

#wordsObject (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.

Returns:

  • (Boolean)


27
28
29
# File 'lib/alfonsox/spellchecker/dictionary/word_list_file.rb', line 27

def word_present?(word)
  @words.include?(word.downcase)
end