levenshteinish 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ -fs
3
+ -Ilib
4
+ -Ispec
5
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in levenshteinish.gemspec
4
+ gemspec
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ levenshteinish (0.0.1)
5
+ hintable_levenshtein
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.2)
11
+ hintable_levenshtein (0.0.3)
12
+ rspec (2.4.0)
13
+ rspec-core (~> 2.4.0)
14
+ rspec-expectations (~> 2.4.0)
15
+ rspec-mocks (~> 2.4.0)
16
+ rspec-core (2.4.0)
17
+ rspec-expectations (2.4.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.4.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ hintable_levenshtein
26
+ levenshteinish!
27
+ rspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "levenshteinish/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "levenshteinish"
7
+ s.version = Levenshteinish::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Linus Oleander"]
10
+ s.email = ["linus@oleander.nu"]
11
+ s.homepage = ""
12
+ s.summary = %q{An implementation of levenshteinish}
13
+ s.description = %q{An basic implementation of levenshteinish}
14
+
15
+ s.rubyforge_project = "levenshteinish"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('hintable_levenshtein')
23
+ s.add_development_dependency('rspec')
24
+ end
@@ -0,0 +1,27 @@
1
+ # Some code borrowed from http://www.erikveen.dds.nl/levenshtein/doc/index.html
2
+ require 'hintable_levenshtein'
3
+
4
+ class Levenshtein
5
+ def self.distance(s1, s2, threshold = nil)
6
+
7
+ # If the arguments is nil
8
+ s1 = s1.to_s unless s1
9
+ s2 = s2.to_s unless s2
10
+
11
+ s1, s2 = s2, s1 if s1.length > s2.length # s1 is the short one; s2 is the long one.
12
+
13
+ if s2.length == 0
14
+ 0.0 # Since s1.length < s2.length, s1 must be empty as well.
15
+ else
16
+ if threshold
17
+ if (d = HintableLevenshtein.new.distance(s1, s2).to_f/s2.length) <= threshold
18
+ d
19
+ else
20
+ nil
21
+ end
22
+ else
23
+ HintableLevenshtein.new.distance(s1, s2).to_f/s2.length
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Levenshteinish
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Levenshtein do
4
+ it "should return the right value when no threshold is being defined" do
5
+ Levenshtein.distance("first", "last").should eq(0.6)
6
+ end
7
+
8
+ it "should return nil value when a threshold is being passed" do
9
+ Levenshtein.distance("first", "last", 0.1).should be_nil
10
+ end
11
+
12
+ it "should not return nil value when a threshold is being passed" do
13
+ Levenshtein.distance("first", "last", 0.8).should_not be_nil
14
+ end
15
+
16
+ it "should not change when a threshold is being passed" do
17
+ Levenshtein.distance("first", "last", 0.8).should eq(0.6)
18
+ end
19
+
20
+ it "should be tested?" do
21
+ Levenshtein.distance("first", "").should eq(1)
22
+ end
23
+
24
+ it "should return zero when to strings are equal" do
25
+ Levenshtein.distance("abc123", "abc123").should eq(0)
26
+ end
27
+
28
+ it "should never return a value larger then 1" do
29
+ Levenshtein.distance("asdasdasdasdasdasdasdasdasdasdasdasd", "a").should <= 1
30
+ end
31
+
32
+ it "should not crash if one if the arguments is nil" do
33
+ lambda do
34
+ Levenshtein.distance(nil, "")
35
+ Levenshtein.distance(nil, nil)
36
+ Levenshtein.distance("", nil)
37
+ end.should_not raise_error
38
+ end
39
+
40
+ it "should return the same value using nil as an empty string" do
41
+ Levenshtein.distance(nil, nil).should eq(Levenshtein.distance("", ""))
42
+ Levenshtein.distance(nil, "Hello").should eq(Levenshtein.distance("", "Hell0"))
43
+ end
44
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require "#{File.dirname(__FILE__)}/../lib/levenshteinish"
3
+
4
+ RSpec.configure do |config|
5
+ config.mock_with :rspec
6
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: levenshteinish
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Linus Oleander
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-30 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: hintable_levenshtein
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: An basic implementation of levenshteinish
47
+ email:
48
+ - linus@oleander.nu
49
+ executables: []
50
+
51
+ extensions: []
52
+
53
+ extra_rdoc_files: []
54
+
55
+ files:
56
+ - .gitignore
57
+ - .rspec
58
+ - Gemfile
59
+ - Gemfile.lock
60
+ - Rakefile
61
+ - levenshteinish.gemspec
62
+ - lib/levenshteinish.rb
63
+ - lib/levenshteinish/version.rb
64
+ - spec/levenshteinish_spec.rb
65
+ - spec/spec_helper.rb
66
+ has_rdoc: true
67
+ homepage: ""
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ requirements: []
92
+
93
+ rubyforge_project: levenshteinish
94
+ rubygems_version: 1.3.7
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: An implementation of levenshteinish
98
+ test_files:
99
+ - spec/levenshteinish_spec.rb
100
+ - spec/spec_helper.rb