fat_core 0.1.14 → 0.2.1

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
  SHA1:
3
- metadata.gz: 743fbec5e5360c89047ded7e33b30772b0029d5d
4
- data.tar.gz: afa6788b68f43119c4bf5f90b580bc9e9c997968
3
+ metadata.gz: b48c133a3c373bf4b5827e7079453c5a7a7a2d5c
4
+ data.tar.gz: 1cf5a94914da4da0c8b4fb4416177fde3917c10a
5
5
  SHA512:
6
- metadata.gz: a56a07d6f10c84655fa00684ea1f9fa769e9bc2d75b1b09c072550d9ca5b664885a1f62a67622aa4df093c68f00c46d34f2a8089ed277bc2fa9a26039b64c722
7
- data.tar.gz: d20b8c5c3abf1884e3689f15bcbf214440a994207d85d38f1d59774e97651f5fa09a90d92302264be95b8eee34c2a5c53e1db0612de5f5edae5e35ddbe12a4cf
6
+ metadata.gz: bab94931282848e1ba912a5239bb02666513a2b3099d12e30b48b39bd99997d938fb4c39c5861f4d18bd75211ca6e680825e02146b34f7bedb82820749f2bcc3
7
+ data.tar.gz: 993dbd9065f30eff2e5d1b0f26fc6b512d796323294cea57e32900c91a149e6b3776f7fbab0e026103b3f83805eaca3fad5dd154f338307c45c5607ac5f8b0f2
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_runtime_dependency "activesupport"
30
30
  spec.add_runtime_dependency "erubis"
31
+ spec.add_runtime_dependency "damerau-levenshtein"
31
32
  end
@@ -1,4 +1,15 @@
1
+ require 'damerau-levenshtein'
2
+
1
3
  class String
4
+ def distance(other, block_size: 1, max_distance: 10)
5
+ dl = DamerauLevenshtein
6
+ # NOTE: DL 'gives up after' max_distance, so the distance function
7
+ # will return max_distance+1 if the distance is bigger than that.
8
+ # Here we subtract 1 so the max_distance also becomes the max
9
+ # return value.
10
+ dl.distance(self, other, block_size, max_distance-1)
11
+ end
12
+
2
13
  # See if self contains colon- or space-separated words that include
3
14
  # the colon- or space-separated words of other. Return the matched
4
15
  # portion of self. Other cannot be a regex embedded in a string.
@@ -1,7 +1,7 @@
1
1
  module FatCore
2
2
  MAJOR = 0
3
- MINOR = 1
4
- PATCH = 14
3
+ MINOR = 2
4
+ PATCH = 1
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
7
7
  end
@@ -196,5 +196,19 @@ the people, for the people, shall not perish from the earth."
196
196
  expect("the hitler-stalin pact".entitle).
197
197
  to eq('The Hitler-Stalin Pact')
198
198
  end
199
+
200
+ it "should be able to compute its Levenshtein distance from another string" do
201
+ expect('Something'.distance('Smoething')).to eq 1
202
+ expect('Something'.distance('Smoething', block_size: 0)).to eq 2
203
+ expect('Something'.distance('meSothing', block_size: 1)).to eq 4
204
+ expect('Something'.distance('meSothing', block_size: 2)).to eq 2
205
+ expect('SomethingElse'.distance('Encyclopedia')).to eq 10
206
+ expect('SomethingElseUnrelated'.
207
+ distance('EncyclopediaBritanica',
208
+ max_distance: 40)).to eq 21
209
+ expect('SomethingElseUnrelated'.
210
+ distance('EncyclopediaBritanica',
211
+ max_distance: 15)).to eq 15
212
+ end
199
213
  end
200
214
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fat_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel E. Doherty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-30 00:00:00.000000000 Z
11
+ date: 2014-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: damerau-levenshtein
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  description: Write a longer description. Optional.
140
154
  email:
141
155
  - ded-law@ddoherty.net