ffi-hunspell 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,11 @@
1
+ ### 0.2.6 / 2013-02-05
2
+
3
+ * Removed the env dependency.
4
+ * Check the returned count from `Hunsepll_stem` in
5
+ {FFI::Hunspell::Dictionary#stem}.
6
+ * Check the returned count from `Hunspell_suggest` in
7
+ {FFI::Hunspell::Dictionary#suggest}.
8
+
1
9
  ### 0.2.5 / 2012-05-11
2
10
 
3
11
  * Load `libhunspell-1.2.so.0` if `libhunspell-1.2.so` cannot be found.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2012 Hal Brodigan
1
+ Copyright (c) 2010-2013 Hal Brodigan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## Description
9
9
 
10
- Ruby FFI bindings for [Hunspell](http://hunspell.sourceforge.net/).
10
+ Ruby FFI bindings for [Hunspell][libhunspell].
11
11
 
12
12
  ## Examples
13
13
 
@@ -47,9 +47,8 @@ Suggest alternate spellings for a word:
47
47
 
48
48
  ## Requirements
49
49
 
50
- * [libhunspell](http://hunspell.sourceforge.net/) >= 1.2.0
51
- * [ffi](https://github.com/ffi/ffi) ~> 1.0
52
- * [env](https://github.com/postmodern/env) ~> 0.2
50
+ * [libhunspell] >= 1.2.0
51
+ * [ffi] ~> 1.0
53
52
 
54
53
  ## Install
55
54
 
@@ -66,6 +65,9 @@ so that {FFI::Hunspell} can find the library:
66
65
 
67
66
  ## License
68
67
 
69
- Copyright (c) 2010-2012 Hal Brodigan
68
+ Copyright (c) 2010-2013 Hal Brodigan
70
69
 
71
70
  See {file:LICENSE.txt} for license information.
71
+
72
+ [libhunspell]: http://hunspell.sourceforge.net/
73
+ [ffi]: https://github.com/ffi/ffi
@@ -1,5 +1,5 @@
1
1
  name: ffi-hunspell
2
- version: 0.2.5
2
+ version: 0.2.6
3
3
  summary: FFI bindings for Hunspell
4
4
  description: Ruby FFI bindings for Hunspell spell checker.
5
5
  license: MIT
@@ -12,7 +12,6 @@ requirements: libhunspell >= 1.2.0
12
12
 
13
13
  dependencies:
14
14
  ffi: ~> 1.0
15
- env: ~> 0.2
16
15
 
17
16
  development_dependencies:
18
17
  rubygems-tasks: ~> 0.1
@@ -19,7 +19,7 @@ module FFI
19
19
  # @param [String] affix_path
20
20
  # The path to the `.aff` file.
21
21
  #
22
- # @param [String] dict_path
22
+ # @param [String] dic_path
23
23
  # The path to the `.dic` file.
24
24
  #
25
25
  # @param [String] key
@@ -165,7 +165,9 @@ module FFI
165
165
  count = Hunspell.Hunspell_stem(self,output,word.to_s)
166
166
  ptr = output.get_pointer(0)
167
167
 
168
- stems = ptr.get_array_of_string(0,count)
168
+ if count > 0
169
+ stems = ptr.get_array_of_string(0,count)
170
+ end
169
171
  end
170
172
 
171
173
  return stems
@@ -187,7 +189,9 @@ module FFI
187
189
  count = Hunspell.Hunspell_suggest(self,output,word.to_s)
188
190
  ptr = output.get_pointer(0)
189
191
 
190
- suggestions = ptr.get_array_of_string(0,count)
192
+ if count > 0
193
+ suggestions = ptr.get_array_of_string(0,count)
194
+ end
191
195
  end
192
196
 
193
197
  return suggestions
@@ -1,5 +1,4 @@
1
1
  require 'ffi'
2
- require 'env'
3
2
 
4
3
  module FFI
5
4
  module Hunspell
@@ -30,7 +29,7 @@ module FFI
30
29
  #
31
30
 
32
31
  # The language to default to, if no 'LANG' env variable was set.
33
- DEFAULT_LANG = 'en_US'
32
+ DEFAULT_LANG = ENV.fetch('LANG','en_US.UTF-8').split('.',2).first
34
33
 
35
34
  #
36
35
  # The default language.
@@ -41,13 +40,13 @@ module FFI
41
40
  # @since 0.2.0
42
41
  #
43
42
  def Hunspell.lang
44
- @lang ||= (Env.lang[0] || DEFAULT_LANG)
43
+ @lang ||= DEFAULT_LANG
45
44
  end
46
45
 
47
46
  #
48
47
  # Sets the default language.
49
48
  #
50
- # @param [String] name
49
+ # @param [String] new_lang
51
50
  # The new language name.
52
51
  #
53
52
  # @return [String]
@@ -65,7 +64,7 @@ module FFI
65
64
  # Known directories to search within for dictionaries.
66
65
  KNOWN_DIRECTORIES = [
67
66
  # User
68
- Env.home.join(USER_DIR),
67
+ File.join(Gem.user_home,USER_DIR),
69
68
  # Debian
70
69
  '/usr/local/share/myspell/dicts',
71
70
  '/usr/share/myspell/dicts',
@@ -9,48 +9,62 @@ describe Hunspell::Dictionary do
9
9
  let(:affix_path) { File.join(Hunspell.directories.last,"#{lang}.aff") }
10
10
  let(:dic_path) { File.join(Hunspell.directories.last,"#{lang}.dic") }
11
11
 
12
- it "should find and open a dictionary file for a given language" do
13
- subject.open(lang) do |dict|
12
+ describe "#initialize" do
13
+ subject { described_class }
14
+
15
+ it "should create a dictionary from '.aff' and '.dic' files" do
16
+ dict = subject.new(affix_path,dic_path)
14
17
  dict.should_not be_nil
18
+
19
+ dict.close
15
20
  end
16
21
  end
17
22
 
18
- it "should create a dictionary from '.aff' and '.dic' files" do
19
- dict = subject.new(affix_path,dic_path)
20
- dict.should_not be_nil
23
+ describe "open" do
24
+ subject { described_class }
21
25
 
22
- dict.close
23
- end
26
+ it "should find and open a dictionary file for a given language" do
27
+ subject.open(lang) do |dict|
28
+ dict.should_not be_nil
29
+ end
30
+ end
24
31
 
25
- it "should close the dictionary" do
26
- dict = subject.open(lang)
27
- dict.close
32
+ it "should close the dictionary" do
33
+ dict = subject.open(lang)
34
+ dict.close
28
35
 
29
- dict.should be_closed
36
+ dict.should be_closed
37
+ end
30
38
  end
31
39
 
40
+ subject { described_class.new(affix_path,dic_path) }
41
+
42
+ after(:all) { subject.close }
43
+
32
44
  it "should provide the encoding of the dictionary files" do
33
- subject.open(lang) do |dict|
34
- dict.encoding.should_not be_empty
35
- end
45
+ subject.encoding.should_not be_empty
36
46
  end
37
47
 
38
48
  it "should check if a word is valid" do
39
- subject.open(lang) do |dict|
40
- dict.should be_valid('dog')
41
- dict.should_not be_valid('dxg')
42
- end
49
+ subject.should be_valid('dog')
50
+ subject.should_not be_valid('dxg')
43
51
  end
44
52
 
45
- it "should find the stems of a word" do
46
- subject.open(lang) do |dict|
47
- dict.stem('fishing').should == %w[fishing fish]
53
+ describe "#stem" do
54
+ it "should find the stems of a word" do
55
+ subject.stem('fishing').should == %w[fishing fish]
56
+ end
57
+
58
+ context "when there are no stems" do
59
+ it "should return []" do
60
+ subject.stem("zzzzzzz").should == []
61
+ end
48
62
  end
49
63
  end
50
64
 
51
- it "should suggest alternate spellings for words" do
52
- subject.open(lang) do |dict|
53
- dict.suggest('arbitrage').should == %w[
65
+ describe "#suggest" do
66
+ it "should suggest alternate spellings for words" do
67
+ subject.suggest('arbitrage').should == %w[
54
68
  arbitrage
55
69
  arbitrages
56
70
  arbitrager
@@ -58,5 +72,11 @@ describe Hunspell::Dictionary do
58
72
  arbitrate
59
73
  ]
60
74
  end
75
+
76
+ context "when there are no suggestions" do
77
+ it "should return []" do
78
+ subject.suggest("________").should == []
79
+ end
80
+ end
61
81
  end
62
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-hunspell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
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-05-12 00:00:00.000000000 Z
12
+ date: 2013-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -27,22 +27,6 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: '1.0'
30
- - !ruby/object:Gem::Dependency
31
- name: env
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: '0.2'
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: '0.2'
46
30
  - !ruby/object:Gem::Dependency
47
31
  name: rubygems-tasks
48
32
  requirement: !ruby/object:Gem::Requirement