Class: Kotoshu::PersonalDictionary

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

Class Method Details

.add_word(word) ⇒ Boolean

Add a word to personal dictionary.

Parameters:

  • word (String)

    Word to add

Returns:

  • (Boolean)

    True if the word was newly added (i.e. it wasn't already in the dictionary); false otherwise.



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_pathString

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.

Returns:

  • (String)


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.

Parameters:

  • word (String)

    Word to check

Returns:

  • (Boolean)

    True if present



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.

Parameters:

  • word (String)

    Word to remove

Returns:

  • (Boolean)

    True if removed



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

.wordsArray<String>

Get all personal words.

Returns:

  • (Array<String>)

    All personal words



46
47
48
# File 'lib/kotoshu/personal_dictionary.rb', line 46

def words
  load_words
end