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 +4 -4
- data/fat_core.gemspec +1 -0
- data/lib/fat_core/string.rb +11 -0
- data/lib/fat_core/version.rb +2 -2
- data/spec/lib/string_spec.rb +14 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b48c133a3c373bf4b5827e7079453c5a7a7a2d5c
|
4
|
+
data.tar.gz: 1cf5a94914da4da0c8b4fb4416177fde3917c10a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bab94931282848e1ba912a5239bb02666513a2b3099d12e30b48b39bd99997d938fb4c39c5861f4d18bd75211ca6e680825e02146b34f7bedb82820749f2bcc3
|
7
|
+
data.tar.gz: 993dbd9065f30eff2e5d1b0f26fc6b512d796323294cea57e32900c91a149e6b3776f7fbab0e026103b3f83805eaca3fad5dd154f338307c45c5607ac5f8b0f2
|
data/fat_core.gemspec
CHANGED
data/lib/fat_core/string.rb
CHANGED
@@ -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.
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/string_spec.rb
CHANGED
@@ -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
|
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
|
+
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
|