dam_lev 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,3 +19,5 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ *.gem
23
+ .bundle
data/Gemfile CHANGED
@@ -1,2 +1,3 @@
1
- gem 'rspec'
2
- gem 'yard'
1
+ source :gemcutter
2
+
3
+ gemspec
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dam_lev (1.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.2)
10
+ rspec (2.1.0)
11
+ rspec-core (~> 2.1.0)
12
+ rspec-expectations (~> 2.1.0)
13
+ rspec-mocks (~> 2.1.0)
14
+ rspec-core (2.1.0)
15
+ rspec-expectations (2.1.0)
16
+ diff-lcs (~> 1.1.2)
17
+ rspec-mocks (2.1.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (>= 1.0.0)
24
+ dam_lev!
25
+ rspec (~> 2.1.0)
data/README.md CHANGED
@@ -16,7 +16,7 @@ DamLev implements the [Damerau–Levenshtein distance algorithm][1]. It is an al
16
16
  DamLev.distance("DamLev", "Damev") # => 1 # deletion
17
17
  DamLev.distance("DamLev", "DamLiev") # => 1 # insertion
18
18
  DamLev.distance("DamLev", "Dam7ev") # => 1 # substitution
19
- DamLev.distance("DamLev", "DameLv") # => 2 # transposition
19
+ DamLev.distance("DamLev", "DameLv") # => 1 # transposition
20
20
 
21
21
  ## Note on Patches/Pull Requests
22
22
 
data/Rakefile CHANGED
@@ -1,46 +1,5 @@
1
- # encoding: utf-8
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
2
3
 
3
- require 'rubygems'
4
- require 'rake'
5
-
6
- begin
7
- require 'jeweler'
8
- Jeweler::Tasks.new do |gem|
9
- gem.name = "dam_lev"
10
- gem.summary = %Q{Measure the distance between two strings.}
11
- gem.description = %Q{Measures the distance between two strings using the Damerau–Levenshtein distance algorithm. For more, see http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance }
12
- gem.email = "blatyo@gmail.com"
13
- gem.homepage = "http://github.com/blatyo/DamLev"
14
- gem.authors = ["Allen Madsen"]
15
- gem.add_development_dependency "rspec", ">= 1.2.9"
16
- gem.add_development_dependency "yard", ">= 0"
17
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
- end
19
- Jeweler::GemcutterTasks.new
20
- rescue LoadError
21
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
- end
23
-
24
- require 'spec/rake/spectask'
25
- Spec::Rake::SpecTask.new(:spec) do |spec|
26
- spec.libs << 'lib' << 'spec'
27
- spec.spec_files = FileList['spec/**/*_spec.rb']
28
- end
29
-
30
- Spec::Rake::SpecTask.new(:rcov) do |spec|
31
- spec.libs << 'lib' << 'spec'
32
- spec.pattern = 'spec/**/*_spec.rb'
33
- spec.rcov = true
34
- end
35
-
36
- task :spec => :check_dependencies
37
- task :default => :spec
38
-
39
- begin
40
- require 'yard'
41
- YARD::Rake::YardocTask.new
42
- rescue LoadError
43
- task :yardoc do
44
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
45
- end
46
- end
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/dam_lev/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "dam_lev"
6
+ s.version = DamLev::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Allen Madsen"]
9
+ s.email = ["blatyo@gmail.com"]
10
+ s.homepage = "http://github.com/blatyo/DamLev"
11
+ s.summary = %q{Measure the distance between two strings.}
12
+ s.description = %q{Measures the distance between two strings using the Damerau–Levenshtein distance algorithm. For more, see http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance }
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.add_development_dependency "rspec", "~> 2.1.0"
16
+ s.add_development_dependency "bundler", ">= 1.0.0"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files`.split("\n").map{|f| f =~ /^(spec\/.*)/ ? $1 : nil}.compact
20
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^(bin\/.*)/ ? $1 : nil}.compact
21
+ s.require_path = 'lib'
22
+ end
@@ -9,13 +9,17 @@ class DamLev
9
9
  (1..str2.length).each do |j|
10
10
  sub_cost = str1[i-1] == str2[j-1] ? 0 : 1
11
11
 
12
- distance_matrix[i][j] = [distance_matrix[i-1][j] + 1, # deletion
13
- distance_matrix[i][j-1] + 1, # insertion
14
- distance_matrix[i-1][j-1] + sub_cost].min # substitution
12
+ distance_matrix[i][j] = [
13
+ distance_matrix[i-1][j] + 1, # deletion
14
+ distance_matrix[i][j-1] + 1, # insertion
15
+ distance_matrix[i-1][j-1] + sub_cost # substitution
16
+ ].min
15
17
 
16
18
  if i > 1 && j > 1 && str1[i-1] == str2[j-2] && str1[i-2] == str2[j-1]
17
- distance_matrix[i+1][j+1] = [distance_matrix[i][j],
18
- distance_matrix[i-2][j-2] + sub_cost].min # transposition
19
+ distance_matrix[i][j] = [
20
+ distance_matrix[i][j],
21
+ distance_matrix[i-2][j-2] + sub_cost # transposition
22
+ ].min
19
23
  end
20
24
  end
21
25
  end
@@ -0,0 +1,3 @@
1
+ class DamLev
2
+ VERSION = "1.0.1"
3
+ end
@@ -18,8 +18,8 @@ describe DamLev do
18
18
  DamLev.distance("DamLev", "Dam7ev").should == 1
19
19
  end
20
20
 
21
- it "should calculate a distance of two when two characters have been swapped between two strings" do
22
- DamLev.distance("DamLev", "DameLv").should == 2
21
+ it "should calculate a distance of one when two characters have been swapped between two strings" do
22
+ DamLev.distance("DamLev", "DameLv").should == 1
23
23
  end
24
24
 
25
25
  it "should calculate a distance equal to the longest string if the other is empty" do
@@ -1,9 +1,2 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'dam_lev'
4
- require 'spec'
5
- require 'spec/autorun'
6
-
7
- Spec::Runner.configure do |config|
8
-
9
- end
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'dam_lev')
2
+ require 'rspec'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 0
9
- version: 1.0.0
8
+ - 1
9
+ version: 1.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Allen Madsen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-04 00:00:00 -04:00
17
+ date: 2010-11-15 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -23,17 +23,17 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ">="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
- - 1
30
29
  - 2
31
- - 9
32
- version: 1.2.9
30
+ - 1
31
+ - 0
32
+ version: 2.1.0
33
33
  type: :development
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: yard
36
+ name: bundler
37
37
  prerelease: false
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
@@ -41,39 +41,42 @@ dependencies:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
43
  segments:
44
+ - 1
44
45
  - 0
45
- version: "0"
46
+ - 0
47
+ version: 1.0.0
46
48
  type: :development
47
49
  version_requirements: *id002
48
50
  description: "Measures the distance between two strings using the Damerau\xE2\x80\x93Levenshtein distance algorithm. For more, see http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance "
49
- email: blatyo@gmail.com
51
+ email:
52
+ - blatyo@gmail.com
50
53
  executables: []
51
54
 
52
55
  extensions: []
53
56
 
54
- extra_rdoc_files:
55
- - LICENSE
56
- - README.md
57
+ extra_rdoc_files: []
58
+
57
59
  files:
58
60
  - .document
59
61
  - .gitignore
60
62
  - .rvmrc
61
63
  - Gemfile
64
+ - Gemfile.lock
62
65
  - LICENSE
63
66
  - README.md
64
67
  - Rakefile
65
- - VERSION
68
+ - dam_lev.gemspec
66
69
  - lib/dam_lev.rb
67
- - spec/DamLev_spec.rb
68
- - spec/spec.opts
70
+ - lib/dam_lev/version.rb
71
+ - spec/dam_lev_spec.rb
69
72
  - spec/spec_helper.rb
70
73
  has_rdoc: true
71
74
  homepage: http://github.com/blatyo/DamLev
72
75
  licenses: []
73
76
 
74
77
  post_install_message:
75
- rdoc_options:
76
- - --charset=UTF-8
78
+ rdoc_options: []
79
+
77
80
  require_paths:
78
81
  - lib
79
82
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -90,8 +93,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
93
  - - ">="
91
94
  - !ruby/object:Gem::Version
92
95
  segments:
93
- - 0
94
- version: "0"
96
+ - 1
97
+ - 3
98
+ - 6
99
+ version: 1.3.6
95
100
  requirements: []
96
101
 
97
102
  rubyforge_project:
@@ -100,5 +105,5 @@ signing_key:
100
105
  specification_version: 3
101
106
  summary: Measure the distance between two strings.
102
107
  test_files:
103
- - spec/DamLev_spec.rb
108
+ - spec/dam_lev_spec.rb
104
109
  - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.0
@@ -1 +0,0 @@
1
- --color