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.

Constant Summary collapse

PERSONAL_FILE =
Kotoshu::Paths.personal_dictionary_path

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 added



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kotoshu/personal_dictionary.rb', line 18

def add_word(word)
  return false if word.nil? || word.empty?

  ensure_directory
  words = load_words

  unless words.include?(word.downcase)
    words << word.downcase
    save_words(words)
  end

  true
end

.include?(word) ⇒ Boolean

Check if word is in personal dictionary.

Parameters:

  • word (String)

    Word to check

Returns:

  • (Boolean)

    True if present



59
60
61
62
63
# File 'lib/kotoshu/personal_dictionary.rb', line 59

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



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/kotoshu/personal_dictionary.rb', line 43

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



35
36
37
# File 'lib/kotoshu/personal_dictionary.rb', line 35

def words
  load_words
end