Class: AlfonsoX::SpellChecker::Dictionary::WordList

Inherits:
Object
  • Object
show all
Defined in:
lib/alfonsox/spellchecker/dictionary/word_list.rb

Overview

Custom dictionary loader composed by a word list

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(word_list) ⇒ WordList

Initialize a AlfonsoX::SpellChecker::Dictionary::WordList

Parameters:

  • word_list (Array<String>)

    Words that are included in this dictionary



15
16
17
# File 'lib/alfonsox/spellchecker/dictionary/word_list.rb', line 15

def initialize(word_list)
  @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.rb', line 11

def words
  @words
end

Class Method Details

.from_config(yml_config) ⇒ Object

Load from Yml



20
21
22
# File 'lib/alfonsox/spellchecker/dictionary/word_list.rb', line 20

def self.from_config(yml_config)
  new(yml_config.fetch('word_list') { [] })
end

Instance Method Details

#word_present?(word) ⇒ Boolean

Inform if a word is present in this dictionary.

Returns:

  • (Boolean)


25
26
27
# File 'lib/alfonsox/spellchecker/dictionary/word_list.rb', line 25

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