levenshtein-ffi 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +12 -4
- data/VERSION +1 -1
- data/levenshtein-ffi.gemspec +11 -11
- data/lib/levenshtein.rb +25 -8
- data/spec/levenshtein_spec.rb +11 -0
- data/spec/spec_helper.rb +0 -2
- metadata +13 -18
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,19 +1,27 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
ffi (1.1.5)
|
5
6
|
git (1.2.5)
|
6
7
|
jeweler (1.6.4)
|
7
8
|
bundler (~> 1.0)
|
8
9
|
git (>= 1.2.5)
|
9
10
|
rake
|
10
11
|
rake (0.9.2)
|
11
|
-
rspec (
|
12
|
+
rspec (2.7.0)
|
13
|
+
rspec-core (~> 2.7.0)
|
14
|
+
rspec-expectations (~> 2.7.0)
|
15
|
+
rspec-mocks (~> 2.7.0)
|
16
|
+
rspec-core (2.7.1)
|
17
|
+
rspec-expectations (2.7.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.7.0)
|
12
20
|
|
13
21
|
PLATFORMS
|
14
22
|
ruby
|
15
23
|
|
16
24
|
DEPENDENCIES
|
17
|
-
ffi
|
25
|
+
ffi (~> 1.1.5)
|
18
26
|
jeweler
|
19
|
-
rspec (=
|
27
|
+
rspec (= 2.7.0)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.3
|
data/levenshtein-ffi.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "1.0.
|
7
|
+
s.name = "levenshtein-ffi"
|
8
|
+
s.version = "1.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Balatero"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2012-08-09"
|
13
|
+
s.description = "Provides a fast, cross-Ruby implementation of the levenshtein distance algorithm."
|
14
|
+
s.email = "dbalatero@gmail.com"
|
15
15
|
s.extensions = ["ext/levenshtein/extconf.rb"]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"README.markdown",
|
@@ -34,27 +34,27 @@ Gem::Specification.new do |s|
|
|
34
34
|
"spec/levenshtein_spec.rb",
|
35
35
|
"spec/spec_helper.rb"
|
36
36
|
]
|
37
|
-
s.homepage =
|
37
|
+
s.homepage = "http://github.com/dbalatero/levenshtein-ffi"
|
38
38
|
s.require_paths = ["lib"]
|
39
|
-
s.rubygems_version =
|
40
|
-
s.summary =
|
39
|
+
s.rubygems_version = "1.8.17"
|
40
|
+
s.summary = "An FFI version of the levenshtein gem."
|
41
41
|
|
42
42
|
if s.respond_to? :specification_version then
|
43
43
|
s.specification_version = 3
|
44
44
|
|
45
45
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
-
s.add_runtime_dependency(%q<ffi>, ["
|
46
|
+
s.add_runtime_dependency(%q<ffi>, ["~> 1.1.5"])
|
47
47
|
s.add_runtime_dependency(%q<ffi>, [">= 0"])
|
48
48
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
49
49
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
50
50
|
else
|
51
|
-
s.add_dependency(%q<ffi>, ["
|
51
|
+
s.add_dependency(%q<ffi>, ["~> 1.1.5"])
|
52
52
|
s.add_dependency(%q<ffi>, [">= 0"])
|
53
53
|
s.add_dependency(%q<rspec>, [">= 0"])
|
54
54
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
55
55
|
end
|
56
56
|
else
|
57
|
-
s.add_dependency(%q<ffi>, ["
|
57
|
+
s.add_dependency(%q<ffi>, ["~> 1.1.5"])
|
58
58
|
s.add_dependency(%q<ffi>, [">= 0"])
|
59
59
|
s.add_dependency(%q<rspec>, [">= 0"])
|
60
60
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
data/lib/levenshtein.rb
CHANGED
@@ -1,12 +1,29 @@
|
|
1
1
|
require 'ffi'
|
2
2
|
|
3
3
|
module Levenshtein
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
class << self
|
5
|
+
extend FFI::Library
|
6
|
+
|
7
|
+
# Try loading in order.
|
8
|
+
library = File.dirname(__FILE__) + "/../ext/levenshtein/levenshtein"
|
9
|
+
candidates = ['.bundle', '.so', '.dylib', ''].map { |ext| library + ext }
|
10
|
+
ffi_lib(candidates)
|
11
|
+
|
12
|
+
# Safe version of distance, checks that arguments are really strings.
|
13
|
+
def distance(str1, str2)
|
14
|
+
validate(str1)
|
15
|
+
validate(str2)
|
16
|
+
ffi_distance(str1, str2)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Unsafe version. Results in a segmentation fault if passed nils!
|
20
|
+
attach_function :ffi_distance, :levenshtein, [:string, :string], :int
|
21
|
+
|
22
|
+
private
|
23
|
+
def validate(arg)
|
24
|
+
unless arg.kind_of?(String)
|
25
|
+
raise TypeError, "wrong argument type #{arg.class} (expected String)"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
12
29
|
end
|
data/spec/levenshtein_spec.rb
CHANGED
@@ -19,4 +19,15 @@ describe Levenshtein do
|
|
19
19
|
Levenshtein.distance(w2, w1).should == d
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
it "should raise an error if either argument is nil" do
|
24
|
+
expect { Levenshtein.distance("", nil) }.to raise_error TypeError
|
25
|
+
expect { Levenshtein.distance(nil, "") }.to raise_error TypeError
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should raise an error if either argument is something else than a string" do
|
29
|
+
expect { Levenshtein.distance("woah", /woah/) }.to raise_error TypeError
|
30
|
+
expect { Levenshtein.distance(5.3, "5.3") }.to raise_error TypeError
|
31
|
+
expect { Levenshtein.distance(Object.new, "Hello") }.to raise_error TypeError
|
32
|
+
end
|
22
33
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: levenshtein-ffi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,23 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
12
|
+
date: 2012-08-09 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: ffi
|
17
|
-
requirement: &
|
16
|
+
requirement: &70329943057740 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
|
-
- -
|
19
|
+
- - ~>
|
21
20
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
21
|
+
version: 1.1.5
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *70329943057740
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: ffi
|
28
|
-
requirement: &
|
27
|
+
requirement: &70329943056940 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
29
|
requirements:
|
31
30
|
- - ! '>='
|
@@ -33,10 +32,10 @@ dependencies:
|
|
33
32
|
version: '0'
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
35
|
+
version_requirements: *70329943056940
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
37
|
name: rspec
|
39
|
-
requirement: &
|
38
|
+
requirement: &70329943056140 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
40
|
requirements:
|
42
41
|
- - ! '>='
|
@@ -44,10 +43,10 @@ dependencies:
|
|
44
43
|
version: '0'
|
45
44
|
type: :development
|
46
45
|
prerelease: false
|
47
|
-
version_requirements: *
|
46
|
+
version_requirements: *70329943056140
|
48
47
|
- !ruby/object:Gem::Dependency
|
49
48
|
name: jeweler
|
50
|
-
requirement: &
|
49
|
+
requirement: &70329943055340 !ruby/object:Gem::Requirement
|
51
50
|
none: false
|
52
51
|
requirements:
|
53
52
|
- - ! '>='
|
@@ -55,7 +54,7 @@ dependencies:
|
|
55
54
|
version: '0'
|
56
55
|
type: :development
|
57
56
|
prerelease: false
|
58
|
-
version_requirements: *
|
57
|
+
version_requirements: *70329943055340
|
59
58
|
description: Provides a fast, cross-Ruby implementation of the levenshtein distance
|
60
59
|
algorithm.
|
61
60
|
email: dbalatero@gmail.com
|
@@ -82,7 +81,6 @@ files:
|
|
82
81
|
- spec/levenshtein_spec.rb
|
83
82
|
- spec/spec_helper.rb
|
84
83
|
- README.markdown.html
|
85
|
-
has_rdoc: true
|
86
84
|
homepage: http://github.com/dbalatero/levenshtein-ffi
|
87
85
|
licenses: []
|
88
86
|
post_install_message:
|
@@ -95,9 +93,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
93
|
- - ! '>='
|
96
94
|
- !ruby/object:Gem::Version
|
97
95
|
version: '0'
|
98
|
-
segments:
|
99
|
-
- 0
|
100
|
-
hash: -3210361372130881473
|
101
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
97
|
none: false
|
103
98
|
requirements:
|
@@ -106,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
101
|
version: '0'
|
107
102
|
requirements: []
|
108
103
|
rubyforge_project:
|
109
|
-
rubygems_version: 1.
|
104
|
+
rubygems_version: 1.8.17
|
110
105
|
signing_key:
|
111
106
|
specification_version: 3
|
112
107
|
summary: An FFI version of the levenshtein gem.
|