ffi-hunspell 0.5.0 → 0.6.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29d0c7a4c75c7cc5f876e6486410f2b6b918660cd2b2be23154791f141997c0b
4
- data.tar.gz: d8108f59f9f508b19be76969cebc5ee1aae2f5ff2591ce540778bec50cf13649
3
+ metadata.gz: b29a3ff5f68640f1c8123c5895074ed2d986961a15fd3f8921baf1bd83769831
4
+ data.tar.gz: fcf088c5e73c7c6dd5ac23db60a8c14c9be58a4dea16e7aa2d0006ed5f019694
5
5
  SHA512:
6
- metadata.gz: b1c9cd2990898a108c8e60242ae5036de97edb26d819f47654d961bf63ab65947ac6ed60141c105c7673bf0f0a08c8345d31109e21e9239e25467ec0a96147e2
7
- data.tar.gz: cd7e8f319039ffe1d946216c87ee504e293c260e5899505bd3f5a4adcf0c8826eabc2f3a16355a8f5c520db824057e88f564f8efccd89a3dfb9993d38bd3c355
6
+ metadata.gz: ef1c370fd0471c1f50748a6c4775313090b5f676c25ed9976932749149905d80c1c02d574ae8dd553ff7d380ddd7f9b5825f30240ec9f17f45e28ff6e98f2007
7
+ data.tar.gz: 365cb6e3fb48e17f1303e76cbd0082e57b0d3d5814f8ff7a2c8c0415fcaa1c3287fedd96ad6c0d94fc2e844d459a07556df38bd5ccd64b6f470c8e75bc860236
@@ -0,0 +1,37 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: ['**']
8
+
9
+ jobs:
10
+ tests:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby:
16
+ - 2.4
17
+ - 2.5
18
+ - 2.6
19
+ - 2.7
20
+ - jruby
21
+ name: Ruby ${{ matrix.ruby }}
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - name: Set up Ruby
25
+ uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby }}
28
+ - name: Install libhunspell
29
+ run: |
30
+ sudo apt update -y && \
31
+ sudo apt install -y --no-install-recommends --no-install-suggests libhunspell-dev hunspell-en-us
32
+ - name: Install dependencies
33
+ run: bundle install --jobs 4 --retry 3
34
+ - name: Run tests
35
+ run: bundle exec rake test
36
+ env:
37
+ LANG: en_US.UTF-8
@@ -1,3 +1,8 @@
1
+ ### 0.6.0 / 2020-11-28
2
+
3
+ * Added {FFI::Hunspell::Dictionary#add_dic} which adds an extra dictionary
4
+ file. (@cdchapman)
5
+
1
6
  ### 0.5.0 / 2019-10-24
2
7
 
3
8
  * Added support for libhunspell-1.7 (@dorner).
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2016 Hal Brodigan
1
+ Copyright (c) 2010-2020 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
@@ -5,8 +5,6 @@
5
5
  * [Documentation](http://rubydoc.info/gems/ffi-hunspell/frames)
6
6
  * [Email](postmodern.mod3 at gmail.com)
7
7
 
8
- [![Build Status](https://secure.travis-ci.org/postmodern/ffi-hunspell.png?branch=master)](https://travis-ci.org/postmodern/ffi-hunspell)
9
-
10
8
  ## Description
11
9
 
12
10
  Ruby FFI bindings for [Hunspell][libhunspell].
@@ -14,6 +12,7 @@ Ruby FFI bindings for [Hunspell][libhunspell].
14
12
  ## Examples
15
13
 
16
14
  Open a dictionary:
15
+
17
16
  ```rb
18
17
  require 'ffi/hunspell'
19
18
 
@@ -31,6 +30,7 @@ dict.close
31
30
  ```
32
31
 
33
32
  Check if a word is valid:
33
+
34
34
  ```rb
35
35
  dict.check?('dog')
36
36
  # => true
@@ -38,30 +38,37 @@ dict.check?('dog')
38
38
  dict.check?('d0g')
39
39
  # => false
40
40
  ```
41
+
41
42
  Find the stems of a word:
43
+
42
44
  ```rb
43
45
  dict.stem('dogs')
44
46
  # => ["dog"]
45
47
  ```
48
+
46
49
  Suggest alternate spellings for a word:
50
+
47
51
  ```rb
48
52
  dict.suggest('arbitrage')
49
53
  # => ["arbitrage", "arbitrages", "arbitrager", "arbitraged", "arbitrate"]
50
54
  ```
55
+
51
56
  ## Requirements
52
57
 
53
- * [libhunspell] >= 1.2.0
58
+ * [libhunspell] >= 1.2.0, <= 1.7.0
54
59
  * [ffi] ~> 1.0
55
60
 
56
61
  ## Install
62
+
57
63
  ```sh
58
64
  $ gem install ffi-hunspell
59
65
  ```
66
+
60
67
  ## License
61
68
 
62
- Copyright (c) 2010-2016 Hal Brodigan
69
+ Copyright (c) 2010-2020 Hal Brodigan
63
70
 
64
71
  See {file:LICENSE.txt} for license information.
65
72
 
66
- [libhunspell]: http://hunspell.sourceforge.net/
73
+ [libhunspell]: http://hunspell.github.io/
67
74
  [ffi]: https://github.com/ffi/ffi
@@ -116,6 +116,8 @@ module FFI
116
116
  Hunspell.Hunspell_add(self,word.to_s)
117
117
  end
118
118
 
119
+ alias << add
120
+
119
121
  #
120
122
  # Adds a word to the dictionary with affix flags.
121
123
  #
@@ -138,7 +140,27 @@ module FFI
138
140
  add_with_affix(word,example)
139
141
  end
140
142
 
141
- alias << add
143
+ #
144
+ # Load an extra dictionary file. The extra dictionaries use the
145
+ # affix file of the allocated Hunspell object.
146
+ #
147
+ # Maximal number of extra dictionaries is limited in the source code (20)
148
+ #
149
+ # @param [String] dic_path
150
+ # The path to the extra `.dic` file.
151
+ #
152
+ # @raise [ArgumentError]
153
+ # The extra `.dic` file did not exist.
154
+ #
155
+ # @since 0.6.0
156
+ #
157
+ def add_dic(dic_path)
158
+ unless File.file?(dic_path)
159
+ raise(ArgumentError,"invalid extra dictionary path #{dic_path.inspect}")
160
+ end
161
+
162
+ Hunspell.Hunspell_add_dic(self,dic_path)
163
+ end
142
164
 
143
165
  #
144
166
  # Removes a word from the dictionary.
@@ -28,6 +28,19 @@ module FFI
28
28
  attach_function :Hunspell_remove, [:pointer, :string], :int
29
29
  attach_function :Hunspell_free_list, [:pointer, :pointer, :int], :void
30
30
 
31
+ begin
32
+ attach_function :Hunspell_add_dic, [:pointer, :string], :int
33
+ rescue FFI::NotFoundError
34
+ def self.method_missing(symbol,*arguments,&block)
35
+ if symbol == :Hunspell_add_dic
36
+ raise NotImplementedError,
37
+ "Hunspell_add_dic was not found in [#{ffi_libraries.map(&:name).join(", ")}]. You must install Hunspell 1.3.4 or later if you need this functionality."
38
+ end
39
+
40
+ super
41
+ end
42
+ end
43
+
31
44
  #
32
45
  # missing functions:
33
46
  #
@@ -2,6 +2,6 @@ module FFI
2
2
  module Hunspell
3
3
  # ffi-hunspell versiont
4
4
  # @since 0.5.0
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
@@ -49,7 +49,7 @@ describe Hunspell::Dictionary do
49
49
  after { subject.close }
50
50
 
51
51
  it "should provide the encoding of the dictionary files" do
52
- expect(subject.encoding).to be Encoding::ISO_8859_1
52
+ expect(subject.encoding).to be_instance_of Encoding
53
53
  end
54
54
 
55
55
  it "should check if a word is valid" do
@@ -57,6 +57,44 @@ describe Hunspell::Dictionary do
57
57
  expect(subject.valid?('dxg')).to be false
58
58
  end
59
59
 
60
+ describe "#add_dic" do
61
+ let(:extra_dic) { File.join(File.dirname(__FILE__),'fixtures/extra.dic') }
62
+
63
+ if FFI::Hunspell.respond_to?(:Hunspell_add_dic)
64
+ context "when libhunspell supports add_dic" do
65
+ before do
66
+ subject.add_dic(extra_dic)
67
+ end
68
+
69
+ it "should add an extra dictionary" do
70
+ expect(subject.add_dic(extra_dic)).to be 0
71
+ end
72
+
73
+ context "when the given extra dictionary file cannot be found" do
74
+ it do
75
+ expect { subject.add_dic('foo') }.to raise_error(ArgumentError)
76
+ end
77
+ end
78
+
79
+ it "should validate a word from the extra dictionary" do
80
+ expect(subject.valid?('dxg')).to be true
81
+ end
82
+
83
+ it "should validate an affixed word based on an affix flag from base affix file" do
84
+ expect(subject.valid?('dxgs')).to be true
85
+ end
86
+ end
87
+ else
88
+ context "when libhunspell does not support add_dic" do
89
+ it "should raise an error" do
90
+ expect {
91
+ subject.add_dic(extra_dic)
92
+ }.to raise_error(NotImplementedError)
93
+ end
94
+ end
95
+ end
96
+ end
97
+
60
98
  describe "#add" do
61
99
  it "should add a word" do
62
100
  expect(subject.add('cat')).to be 0
@@ -0,0 +1,2 @@
1
+ 1
2
+ dxg/MS
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-hunspell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-25 00:00:00.000000000 Z
11
+ date: 2020-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -48,9 +48,9 @@ extra_rdoc_files:
48
48
  - README.md
49
49
  files:
50
50
  - ".gemtest"
51
+ - ".github/workflows/ruby.yml"
51
52
  - ".gitignore"
52
53
  - ".rspec"
53
- - ".travis.yml"
54
54
  - ".yardopts"
55
55
  - ChangeLog.md
56
56
  - Gemfile
@@ -64,6 +64,7 @@ files:
64
64
  - lib/ffi/hunspell/hunspell.rb
65
65
  - lib/ffi/hunspell/version.rb
66
66
  - spec/dictionary_spec.rb
67
+ - spec/fixtures/extra.dic
67
68
  - spec/hunspell_spec.rb
68
69
  - spec/spec_helper.rb
69
70
  homepage: https://github.com/postmodern/ffi-hunspell#readme
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  version: '0'
87
88
  requirements:
88
89
  - libhunspell >= 1.2.0, <= 1.7.0
89
- rubygems_version: 3.0.3
90
+ rubygems_version: 3.1.4
90
91
  signing_key:
91
92
  specification_version: 4
92
93
  summary: FFI bindings for Hunspell
@@ -1,9 +0,0 @@
1
- language: ruby
2
- before_install:
3
- - sudo apt-get install libhunspell-dev hunspell-en-us
4
- - gem install bundler -v "~> 2.0"
5
- rvm:
6
- - 2.5
7
- - 2.6
8
- - jruby
9
- script: bundle exec rake spec