Module: Kotoshu::Dictionary

Defined in:
lib/kotoshu/dictionary.rb,
lib/kotoshu/dictionary/base.rb,
lib/kotoshu/dictionary/cspell.rb,
lib/kotoshu/dictionary/custom.rb,
lib/kotoshu/dictionary/unified.rb,
lib/kotoshu/dictionary/hunspell.rb,
lib/kotoshu/dictionary/plain_text.rb,
lib/kotoshu/dictionary/repository.rb,
lib/kotoshu/dictionary/unix_words.rb

Overview

Dictionary backends for different formats (Hunspell, CSpell, plain text, etc.).

Defined Under Namespace

Classes: Base, CSpell, Custom, Hunspell, PlainText, Repository, Unified, UnixWords

Class Method Summary collapse

Class Method Details

.load(type, *args) ⇒ Base

Load a dictionary by type.

Examples:

Loading a dictionary

dict = Dictionary.load(:unix_words, "/usr/share/dict/words",
                       language_code: "en-US")

Parameters:

  • type (Symbol)

    The dictionary type

  • args (Array)

    Arguments to pass to constructor

Returns:

  • (Base)

    The loaded dictionary

Raises:



256
257
258
259
260
261
# File 'lib/kotoshu/dictionary/base.rb', line 256

def self.load(type, *args)
  klass = registry[type]
  raise ConfigurationError, "Unknown dictionary type: #{type}" unless klass

  klass.new(*args)
end

.register_type(type, klass) ⇒ Object

Register a dictionary type.

Examples:

Registering a custom dictionary type

Dictionary.register_type(:my_custom, MyDictionary)

Parameters:

  • type (Symbol)

    The type key

  • klass (Class)

    The dictionary class



242
243
244
245
# File 'lib/kotoshu/dictionary/base.rb', line 242

def self.register_type(type, klass)
  @registry ||= {}
  @registry[type] = klass
end

.registryHash

Module-level registry for dictionary types.

Returns:

  • (Hash)

    Registry of type keys to classes



231
232
233
# File 'lib/kotoshu/dictionary/base.rb', line 231

def self.registry
  @registry ||= {}
end