Module: FFI::Aspell

Extended by:
Library
Defined in:
lib/ffi/aspell/aspell.rb,
lib/ffi/aspell/error.rb,
lib/ffi/aspell/speller.rb,
lib/ffi/aspell/version.rb

Overview

FFI::Aspell is an FFI binding for the Aspell spell checking library. Basic usage is as following:

require 'ffi/aspell'

speller = FFI::Aspell::Speller.new

speller.correct?('cookie') # => true
speller.correct?('cookei') # => false

For more information see Speller.

Defined Under Namespace

Classes: ConfigError, DictInfo, Speller

Constant Summary collapse

VERSION =
'1.1.0'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.config_delete(config) ⇒ Object

Removes a config pointer and frees the memory associated with said pointer.

Parameters:

  • config (FFI::Pointer)

    The pointer to remove.



46
47
48
49
# File 'lib/ffi/aspell/aspell.rb', line 46

attach_function 'config_delete',
'delete_aspell_config',
[:pointer],
:void

.config_newFFI::Pointer

Creates a pointer for a configuration struct.

Returns:

  • (FFI::Pointer)


33
34
35
36
# File 'lib/ffi/aspell/aspell.rb', line 33

attach_function 'config_new',
'new_aspell_config',
[],
:pointer

.config_remove(config, key) ⇒ TrueClass|FalseClass

Sets the value of the specified configuration item back to its default value.

Examples:

config = FFI::Aspell.config_new

FFI::Aspell.config_replace(config, 'lang', 'nl')
FFI::Aspell.config_remove(config, 'lang')

Parameters:

  • config (FFI::Pointer)

    Pointer to the configuration struct.

  • key (String)

    The name of the configuration item to reset.

Returns:

  • (TrueClass|FalseClass)


120
121
122
123
# File 'lib/ffi/aspell/aspell.rb', line 120

attach_function 'config_remove',
'aspell_config_remove',
[:pointer, :string],
:bool

.config_replace(config, key, value) ⇒ TrueClass|FalseClass

Sets the new value of the specified configuration item.

Examples:

config = FFI::Aspell.config_new

FFI::Aspell.config_replace(config, 'lang', 'nl')

Parameters:

  • config (FFI::Pointer)

    Pointer to the configuration struct.

  • key (String)

    The name of the configuration item to set.

  • value (String)

    The new value of the configuration item.

Returns:

  • (TrueClass|FalseClass)


99
100
101
102
# File 'lib/ffi/aspell/aspell.rb', line 99

attach_function 'config_replace',
'aspell_config_replace',
[:pointer, :string, :string],
:bool

.config_retrieve(config, key) ⇒ String

Retrieves the value of a given configuration item. The value is returned as a string or nil upon failure.

Examples:

config = FFI::Aspell.config_new
value  = FFI::Aspell.config_retrieve(config, 'lang')

puts value # => "en_US"

Parameters:

  • config (FFI::Pointer)

    A pointer to a configuration struct.

  • key (String)

    The name of the configuration item to retrieve.

Returns:

  • (String)


67
68
69
70
# File 'lib/ffi/aspell/aspell.rb', line 67

attach_function 'config_retrieve',
'aspell_config_retrieve',
[:pointer, :string],
:string

.config_retrieve_default(config, key) ⇒ Object

Retrieves the default value of a configuration item.

See Also:



79
80
81
82
# File 'lib/ffi/aspell/aspell.rb', line 79

attach_function 'config_retrieve_default',
'aspell_config_get_default',
[:pointer, :string],
:string

.delete_dict_info_enumeration(enumeration) ⇒ Object

Deletes an enumeration of dictionaries.

Parameters:



295
296
297
298
# File 'lib/ffi/aspell/aspell.rb', line 295

attach_function 'delete_dict_info_enumeration',
'delete_aspell_dict_info_enumeration',
[:pointer],
:void

.dict_info_enumeration_next(elements) ⇒ DictInfo|NilClass

Retrieves the next element in the list of dictionaries.

Parameters:

Returns:

  • (DictInfo|NilClass)

    dictInfo Returns an object of DictInfo information, which contains dictionary information.



310
311
312
313
# File 'lib/ffi/aspell/aspell.rb', line 310

attach_function 'dict_info_enumeration_next',
'aspell_dict_info_enumeration_next',
[:pointer],
DictInfo

.dict_info_list(config) ⇒ FFI::Pointer

Gets a list of all installed aspell dictionaries.

by dict_info_list_elements.

Parameters:

  • config (FFI::Pointer)

Returns:

  • (FFI::Pointer)

    list A list of dictionaries which can be used



267
268
269
270
# File 'lib/ffi/aspell/aspell.rb', line 267

attach_function 'dict_info_list',
'get_aspell_dict_info_list',
[:pointer],
:pointer

.dict_info_list_elements(list) ⇒ FFI::Pointer

Gets all elements from the dictionary list.

Parameters:

  • list (FFI::Pointer)

    A list of dictionaries as returned by dict_info_list.

Returns:

  • (FFI::Pointer)

    dictionary Returns an enumeration of DictInfo structs.



282
283
284
285
# File 'lib/ffi/aspell/aspell.rb', line 282

attach_function 'dict_info_list_elements',
'aspell_dict_info_list_elements',
[:pointer],
:pointer

.speller_check(speller, word, length) ⇒ TrueClass|FalseClass

Checks if a given word is spelled correctly or not. If the word is valid true will be returned, false otherwise.

Examples:

config  = FFI::Aspell.config_new
speller = FFI::Aspell.speller_new(config)
word    = 'cookie'
valid   = FFI::Aspell.speller_check(speller, word, word.length)

if valid
  puts 'The word "cookie" is valid'
else
  puts 'The word "cookie" is invalid'
end

Parameters:

  • speller (FFI::Pointer)

    Pointer to a speller struct to use.

  • word (String)

    The word to check.

  • length (Fixnum)

    The length of the word.

Returns:

  • (TrueClass|FalseClass)


181
182
183
184
# File 'lib/ffi/aspell/aspell.rb', line 181

attach_function 'speller_check',
'aspell_speller_check',
[:pointer, :string, :int],
:bool

.speller_delete(speller) ⇒ Object

Removes a speller pointer and frees the memory associated with said pointer.

Parameters:

  • speller (FFI::Pointer)

    The pointer to remove.



153
154
155
156
# File 'lib/ffi/aspell/aspell.rb', line 153

attach_function 'speller_delete',
'delete_aspell_speller',
[:pointer],
:void

.speller_new(config) ⇒ FFI::Pointer

Creates a pointer to a speller struct.

Examples:

config  = FFI::Aspell.config_new
speller = FFI::Aspell.speller_new(config)

Parameters:

  • config (FFI::Pointer)

    The configuration struct to use for the speller.

Returns:

  • (FFI::Pointer)


140
141
142
143
# File 'lib/ffi/aspell/aspell.rb', line 140

attach_function 'speller_new',
'new_aspell_speller',
[:pointer],
:pointer

.string_enumeration_delete(elements) ⇒ Object

Removes the pointer returned by word_list_elements and frees the associated memory.

Parameters:

  • elements (FFI::Pointer)

    A pointer for a list of elements as returned by word_list_elements.



225
226
227
228
# File 'lib/ffi/aspell/aspell.rb', line 225

attach_function 'string_enumeration_delete',
'delete_aspell_string_enumeration',
[:pointer],
:void

.string_enumeration_next(elements) ⇒ String|NilClass

Retrieves the next item in the list of suggestions.

Examples:

speller  = FFI::Aspell.speller_new(FFI::Aspell.config_new)
word     = 'cookie'
list     = FFI::Aspell.speller_suggest(speller, word, word.length)
elements = FFI::Aspell.word_list_elements(list)
words    = []

while word = FFI::Aspell.string_enumeration_next(elements)
  words << word
end

FFI::Aspell.string_enumeration_delete(elements)
FFI::Aspell.speller_delete(speller)

Parameters:

  • elements (FFI::Pointer)

    Pointer to a list of elements as returned by word_list_elements.

Returns:

  • (String|NilClass)


253
254
255
256
# File 'lib/ffi/aspell/aspell.rb', line 253

attach_function 'string_enumeration_next',
'aspell_string_enumeration_next',
[:pointer],
:string

.word_list_elements(suggestions) ⇒ FFI::Pointer

Returns a pointer to a list which can be used by string_enumeration_next to retrieve all the suggested words.

Parameters:

  • suggestions (FFI::Pointer)

    A pointer with suggestions as returned by speller_suggest

Returns:

  • (FFI::Pointer)


211
212
213
214
# File 'lib/ffi/aspell/aspell.rb', line 211

attach_function 'word_list_elements',
'aspell_word_list_elements',
[:pointer],
:pointer

Instance Method Details

#speller_suggest(speller, word, length) ⇒ FFI::Pointer

Returns a pointer that can be used to retrieve a list of suggestions for a given word.

Returns:

  • (FFI::Pointer)

See Also:



196
197
198
199
# File 'lib/ffi/aspell/aspell.rb', line 196

attach_function 'speller_suggest',
'aspell_speller_suggest',
[:pointer, :string, :int],
:pointer