fuzzy_ruby 0.0.0 → 0.0.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/lib/fuzzy_ruby.rb +22 -22
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b92009d6bd7c02e372100e053a821dfe37cc233
|
4
|
+
data.tar.gz: 3d4b96c499d30f52c4004ecf78f16814fa2a42f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 405ca1cb09b2d97a267456bb3dc75c5ddb581cdd75d21c6aaf6aad22ea68aa6a69bdff956db854be81f0923a9891e8cc8edeec59eacccb1218114c39a2672d9e
|
7
|
+
data.tar.gz: 63e25bd23e692b8ce164f5ef1ebab0a04cd24ea4d5fa9530f7f06398421816cfe021a5e618cd66bb1100589422c284d316b62a7bc399af18f5d1c499aedbf461
|
data/lib/fuzzy_ruby.rb
CHANGED
@@ -34,31 +34,31 @@ class Fuzzy
|
|
34
34
|
return ret
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
regexp << "(\w*)"
|
37
|
+
# build the regular expression
|
38
|
+
def self.build_regexp(string)
|
39
|
+
regexp = ""
|
40
|
+
string.each_char do |c|
|
41
|
+
regexp << "(\w*)#{c}"
|
44
42
|
end
|
43
|
+
regexp << "(\w*)"
|
44
|
+
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
@weights[index] += weight
|
54
|
-
if !done(index)
|
55
|
-
@strings[index] = @strings[index][weight+1..@strings[index].length]
|
56
|
-
assign_weights(index, /#{regexp.source[5..regexp.source.length]}/)
|
57
|
-
end
|
46
|
+
# recursive function to assign weight to string
|
47
|
+
# once there is match, removes one character from the reg exp and repeat
|
48
|
+
def self.assign_weights(index, regexp)
|
49
|
+
weight = @strings[index] =~ regexp
|
50
|
+
if weight == nil
|
51
|
+
return
|
58
52
|
end
|
59
|
-
|
60
|
-
|
61
|
-
@strings[index]
|
53
|
+
@weights[index] += (weight+1)
|
54
|
+
if !done(index)
|
55
|
+
@strings[index] = @strings[index][weight+1..@strings[index].length]
|
56
|
+
assign_weights(index, /#{regexp.source[5..regexp.source.length]}/)
|
62
57
|
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.done(index)
|
61
|
+
@strings[index] == nil || @weights[index] == -1 ? true : false
|
62
|
+
end
|
63
63
|
|
64
64
|
end
|