Class: Kotoshu::PersonalDictionary
- Inherits:
-
Object
- Object
- Kotoshu::PersonalDictionary
- Defined in:
- lib/kotoshu/personal_dictionary.rb
Overview
Personal dictionary for user-specific words.
Stored in ~/.config/kotoshu/personal.dic (Hunspell format) under the XDG config directory. Override via KOTOSHU_PERSONAL_DIC.
The on-disk path is resolved lazily on every call so env-var overrides take effect at runtime — handy for tests and for users who set KOTOSHU_PERSONAL_DIC after the gem loads.
Class Method Summary collapse
-
.add_word(word) ⇒ Boolean
Add a word to personal dictionary.
-
.file_path ⇒ String
Resolve the personal-dictionary file path from Paths (which honors KOTOSHU_PERSONAL_DIC).
-
.include?(word) ⇒ Boolean
Check if word is in personal dictionary.
-
.remove_word(word) ⇒ Boolean
Remove a word from personal dictionary.
-
.words ⇒ Array<String>
Get all personal words.
Class Method Details
.add_word(word) ⇒ Boolean
Add a word to personal dictionary.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/kotoshu/personal_dictionary.rb', line 30 def add_word(word) return false if word.nil? || word.empty? ensure_directory words = load_words return false if words.include?(word.downcase) words << word.downcase save_words(words) true end |
.file_path ⇒ String
Resolve the personal-dictionary file path from Paths (which honors KOTOSHU_PERSONAL_DIC). Read fresh each call so an env override applied after gem load still takes effect.
21 22 23 |
# File 'lib/kotoshu/personal_dictionary.rb', line 21 def file_path Kotoshu::Paths.personal_dictionary_path end |
.include?(word) ⇒ Boolean
Check if word is in personal dictionary.
70 71 72 73 74 |
# File 'lib/kotoshu/personal_dictionary.rb', line 70 def include?(word) return false if word.nil? || word.empty? load_words.include?(word.downcase) end |
.remove_word(word) ⇒ Boolean
Remove a word from personal dictionary.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kotoshu/personal_dictionary.rb', line 54 def remove_word(word) return false if word.nil? || word.empty? words = load_words if words.delete(word.downcase) save_words(words) true else false end end |
.words ⇒ Array<String>
Get all personal words.
46 47 48 |
# File 'lib/kotoshu/personal_dictionary.rb', line 46 def words load_words end |