Module: FFI::Hunspell

Extended by:
Library
Defined in:
lib/ffi/hunspell/hunspell.rb,
lib/ffi/hunspell/dictionary.rb

Defined Under Namespace

Classes: Dictionary

Constant Summary collapse

DEFAULT_LANG =

The language to default to, if no 'LANG' env variable was set.

'en_US'
USER_DIR =

The directory name used to store user installed dictionaries.

'.hunspell_default'
KNOWN_DIRECTORIES =

Known directories to search within for dictionaries.

[
  # User
  Env.home.join(USER_DIR),
  # Debian
  '/usr/local/share/myspell/dicts',
  '/usr/share/myspell/dicts',
  # Fedora
  '/usr/local/share/myspell',
  '/usr/share/myspell',
  # Mac Ports
  '/opt/local/share/hunspell',
  '/opt/share/hunspell'
]

Class Method Summary collapse

Class Method Details

.dict(name = Hunspell.lang) {|dict| ... } ⇒ nil

Opens a Hunspell dictionary.

Parameters:

  • name (Symbol, String) (defaults to: Hunspell.lang)

    The name of the dictionary to open.

Yields:

  • (dict)

    The given block will be passed the Hunspell dictionary.

Yield Parameters:

Returns:

  • (nil)


107
108
109
# File 'lib/ffi/hunspell/hunspell.rb', line 107

def Hunspell.dict(name=Hunspell.lang,&block)
  Dictionary.open(name,&block)
end

.directoriesArray<String, Pathname>

The dictionary directories to search for dictionary files.

Returns:

  • (Array<String, Pathname>)

    The directory paths.

Since:

  • 0.2.0



87
88
89
90
91
# File 'lib/ffi/hunspell/hunspell.rb', line 87

def Hunspell.directories
  @directories ||= KNOWN_DIRECTORIES.select do |path|
    File.directory?(path)
  end
end

.langString

The default language.

Returns:

  • (String)

    The name of the default language.

Since:

  • 0.2.0



42
43
44
# File 'lib/ffi/hunspell/hunspell.rb', line 42

def Hunspell.lang
  @lang ||= (Env.lang[0] || DEFAULT_LANG)
end

.lang=(new_lang) ⇒ String

Sets the default language.

Parameters:

  • name (String)

    The new language name.

Returns:

  • (String)

    The name of the new default language.

Since:

  • 0.2.0



57
58
59
# File 'lib/ffi/hunspell/hunspell.rb', line 57

def Hunspell.lang=(new_lang)
  @lang = new_lang.to_s
end