class AlfonsoX::SpellChecker::Dictionary::WordListFile

Custom dictionary loader composed by a word list from a file

Attributes

words[R]

Public Class Methods

from_config(yml_config) click to toggle source

Load from Yml

# File lib/alfonsox/spellchecker/dictionary/word_list_file.rb, line 22
def self.from_config(yml_config)
  new(yml_config['path'])
end
new(word_list_file_path) click to toggle source

Initialize a AlfonsoX::SpellChecker::Dictionary::WordListFile from a file path. Note the words must be in different lines. @param [String] word_list_file_path Word list file path.

# 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

Public Instance Methods

word_present?(word) click to toggle source

Inform if a word is present in this dictionary.

# File lib/alfonsox/spellchecker/dictionary/word_list_file.rb, line 27
def word_present?(word)
  @words.include?(word.downcase)
end