ffi-aspell 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/README.md +2 -1
- data/ffi-aspell.gemspec +1 -1
- data/lib/ffi/aspell/speller.rb +45 -3
- data/lib/ffi/aspell/version.rb +1 -1
- data/spec/ffi/aspell/speller.rb +9 -0
- data/spec/ffi/aspell/suggestions.rb +12 -0
- data/spec/helper.rb +17 -0
- metadata +4 -4
- data/.gems +0 -5
- data/.rvmrc +0 -1
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p194
|
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -8,6 +8,7 @@ the main author as of April 2012.
|
|
8
8
|
|
9
9
|
* FFI: `gem install ffi`
|
10
10
|
* Aspell (`sudo pacman -S aspell` if you're on Arch Linux)
|
11
|
+
* Dutch and Greek language packs for Aspell.
|
11
12
|
|
12
13
|
## Usage
|
13
14
|
|
@@ -37,7 +38,7 @@ For more information see the YARD documentation.
|
|
37
38
|
1. Make sure that Aspell and the English and Dutch dictionaries for it are
|
38
39
|
installed as well. On Arch Linux this can be done by running `sudo pacman -S
|
39
40
|
aspell aspell-en aspell-nl`.
|
40
|
-
2.
|
41
|
+
2. Install the gems: `bundle install`
|
41
42
|
3. Run the tests to see if everything is working: `rake test`
|
42
43
|
4. Hack away!
|
43
44
|
|
data/ffi-aspell.gemspec
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../lib/ffi/aspell/version', __FILE__)
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'ffi-aspell'
|
5
5
|
s.version = FFI::Aspell::VERSION
|
6
|
-
s.date = '2012-
|
6
|
+
s.date = '2012-07-07'
|
7
7
|
s.authors = ['Yorick Peterse']
|
8
8
|
s.email = 'yorickpeterse@gmail.com'
|
9
9
|
s.summary = 'FFI bindings for Aspell'
|
data/lib/ffi/aspell/speller.rb
CHANGED
@@ -118,7 +118,11 @@ module FFI
|
|
118
118
|
end
|
119
119
|
|
120
120
|
speller = Aspell.speller_new(@config)
|
121
|
-
correct = Aspell.speller_check(
|
121
|
+
correct = Aspell.speller_check(
|
122
|
+
speller,
|
123
|
+
handle_input(word.to_s),
|
124
|
+
word.bytesize
|
125
|
+
)
|
122
126
|
|
123
127
|
Aspell.speller_delete(speller)
|
124
128
|
|
@@ -139,12 +143,16 @@ module FFI
|
|
139
143
|
end
|
140
144
|
|
141
145
|
speller = Aspell.speller_new(@config)
|
142
|
-
list = Aspell.speller_suggest(
|
146
|
+
list = Aspell.speller_suggest(
|
147
|
+
speller,
|
148
|
+
handle_input(word),
|
149
|
+
word.bytesize
|
150
|
+
)
|
143
151
|
suggestions = []
|
144
152
|
elements = Aspell.word_list_elements(list)
|
145
153
|
|
146
154
|
while word = Aspell.string_enumeration_next(elements)
|
147
|
-
suggestions << word
|
155
|
+
suggestions << handle_output(word)
|
148
156
|
end
|
149
157
|
|
150
158
|
Aspell.string_enumeration_delete(elements)
|
@@ -267,6 +275,40 @@ module FFI
|
|
267
275
|
)
|
268
276
|
end
|
269
277
|
end
|
278
|
+
|
279
|
+
##
|
280
|
+
# Converts word to encoding expected in aspell
|
281
|
+
# from current ruby encoding
|
282
|
+
#
|
283
|
+
# @param [String] word The word to convert
|
284
|
+
# return [String] word
|
285
|
+
#
|
286
|
+
def handle_input(word)
|
287
|
+
if defined?(Encoding)
|
288
|
+
enc = get('encoding')
|
289
|
+
word.encode!(enc)
|
290
|
+
end
|
291
|
+
|
292
|
+
word
|
293
|
+
end
|
294
|
+
private :handle_input
|
295
|
+
|
296
|
+
##
|
297
|
+
# Converts word from aspell encoding to what ruby expects
|
298
|
+
#
|
299
|
+
# @param [String] word The word to convert
|
300
|
+
# return [String] word
|
301
|
+
#
|
302
|
+
def handle_output(word)
|
303
|
+
if defined?(Encoding)
|
304
|
+
enc = get('encoding')
|
305
|
+
word.force_encoding(enc).encode!
|
306
|
+
end
|
307
|
+
|
308
|
+
word
|
309
|
+
end
|
310
|
+
private :handle_output
|
311
|
+
|
270
312
|
end # Speller
|
271
313
|
end # Aspell
|
272
314
|
end # FFI
|
data/lib/ffi/aspell/version.rb
CHANGED
data/spec/ffi/aspell/speller.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
1
3
|
require File.expand_path('../../../helper', __FILE__)
|
2
4
|
|
3
5
|
describe 'FFI::Aspell::Speller' do
|
@@ -60,6 +62,13 @@ describe 'FFI::Aspell::Speller' do
|
|
60
62
|
speller.correct?('huis').should == true
|
61
63
|
end
|
62
64
|
|
65
|
+
it 'Validate some UTF-8 (Greek) words' do
|
66
|
+
speller = FFI::Aspell::Speller.new('el')
|
67
|
+
|
68
|
+
speller.correct?('χταπόδι').should == true
|
69
|
+
speller.correct?('οιρανός').should == false
|
70
|
+
end
|
71
|
+
|
63
72
|
it 'Change the language of an existing speller object' do
|
64
73
|
speller = FFI::Aspell::Speller.new
|
65
74
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
1
3
|
require File.expand_path('../../../helper', __FILE__)
|
2
4
|
|
3
5
|
describe 'FFI::Aspell::Speller#suggestions' do
|
@@ -10,6 +12,16 @@ describe 'FFI::Aspell::Speller#suggestions' do
|
|
10
12
|
suggestions.include?('cooked').should == true
|
11
13
|
end
|
12
14
|
|
15
|
+
it 'Return a list of UTF-8 words' do
|
16
|
+
with_internal_encoding('UTF-8') do
|
17
|
+
speller = FFI::Aspell::Speller.new('el')
|
18
|
+
suggestions = speller.suggestions('χταπίδι')
|
19
|
+
|
20
|
+
suggestions.include?('χταπόδι').should == true
|
21
|
+
suggestions.include?('απίδι').should == true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
13
25
|
it 'Return a list of word suggestions using the "bad-spellers" mode' do
|
14
26
|
speller = FFI::Aspell::Speller.new
|
15
27
|
|
data/spec/helper.rb
CHANGED
@@ -5,3 +5,20 @@ Bacon.extend(Bacon::TapOutput)
|
|
5
5
|
Bacon.summary_on_exit
|
6
6
|
|
7
7
|
FIXTURES = File.expand_path('../fixtures', __FILE__)
|
8
|
+
|
9
|
+
##
|
10
|
+
# Used to change default internal encoding for certain tests.
|
11
|
+
# Ruby uses default_internal (amongst others) when presenting
|
12
|
+
# strings and when calling encode! without argument.
|
13
|
+
# Rails explicitly sets it to UTF-8 on bootup
|
14
|
+
#
|
15
|
+
# @param [String] enc The encoding to switch to
|
16
|
+
#
|
17
|
+
def with_internal_encoding(enc)
|
18
|
+
if defined?(Encoding)
|
19
|
+
old_enc = Encoding.default_internal
|
20
|
+
Encoding.default_internal = enc
|
21
|
+
yield
|
22
|
+
Encoding.default_internal = old_enc
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-aspell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -97,10 +97,10 @@ executables: []
|
|
97
97
|
extensions: []
|
98
98
|
extra_rdoc_files: []
|
99
99
|
files:
|
100
|
-
- .gems
|
101
100
|
- .gitignore
|
102
|
-
- .
|
101
|
+
- .ruby-version
|
103
102
|
- .yardopts
|
103
|
+
- Gemfile
|
104
104
|
- LICENSE
|
105
105
|
- README.md
|
106
106
|
- Rakefile
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use --create 1.9.3@ffi-aspell
|