Module: FFI::Aspell

Extended by:
Library
Defined in:
lib/ffi/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.

Since:

  • 13-04-2012

Defined Under Namespace

Classes: ConfigError, Speller

Constant Summary collapse

VERSION =

Since:

  • 13-04-2012

'0.0.3'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.config_newFFI::Pointer

Creates a pointer for a configuration struct.

Returns:

  • (FFI::Pointer)

Since:

  • 24-04-2012



35
36
37
38
# File 'lib/ffi/aspell.rb', line 35

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)

Since:

  • 24-04-2012



113
114
115
116
# File 'lib/ffi/aspell.rb', line 113

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)

Since:

  • 24-04-2012



91
92
93
94
# File 'lib/ffi/aspell.rb', line 91

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)

Since:

  • 24-04-2012



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

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:

Since:

  • 24-04-2012



70
71
72
73
# File 'lib/ffi/aspell.rb', line 70

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

.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)

Since:

  • 24-04-2012



177
178
179
180
# File 'lib/ffi/aspell.rb', line 177

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.

Since:

  • 24-04-2012



148
149
150
151
# File 'lib/ffi/aspell.rb', line 148

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)

Since:

  • 24-04-2012



134
135
136
137
# File 'lib/ffi/aspell.rb', line 134

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.

Since:

  • 24-04-2012



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

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)

Since:

  • 24-04-2012



253
254
255
256
# File 'lib/ffi/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)

Since:

  • 24-04-2012



209
210
211
212
# File 'lib/ffi/aspell.rb', line 209

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:

Since:

  • 24-04-2012



193
194
195
196
# File 'lib/ffi/aspell.rb', line 193

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