enf 0.1.0 → 0.1.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/README.md +7 -1
- data/lib/enf/suggest.rb +22 -15
- data/lib/enf/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3aa05a4afb0adf081ecd35a98ddadf81357da91a
|
4
|
+
data.tar.gz: db6ccc6c863db56f53d83f1ac43a1d51bf73a034
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 374795893779728a8ff20c8dd353965191f082846f82c20b940854f2ec1bea05c82920979004ba7f3115e46044b65844d605dba2d5c47b3de8b599d4bed5e706
|
7
|
+
data.tar.gz: 6387e0246377d173da7aa5bc6acffa29edbbae42a048ebb353ae000b93e98f493e80947e7c46f212ad108bb50e78dd5e7d2c2752097abab7210d831596a36e7c
|
data/README.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
Memory lightweight implementation of a white/black list
|
4
4
|
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install enf
|
9
|
+
```
|
10
|
+
|
5
11
|
## Examples
|
6
12
|
|
7
13
|
*Building a dictionnary of all terms used in 'Les misérables'*
|
@@ -106,7 +112,7 @@ Enf::Elephant are now able to propose completion candidates from a word
|
|
106
112
|
beginning, thanks to the 'suggest' method:
|
107
113
|
|
108
114
|
```ruby
|
109
|
-
require 'enf/suggest
|
115
|
+
require 'enf/suggest'
|
110
116
|
require 'open-uri'
|
111
117
|
URI = 'https://www.gutenberg.org/ebooks/135.txt.utf-8'
|
112
118
|
|
data/lib/enf/suggest.rb
CHANGED
@@ -24,25 +24,32 @@ module Enf
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def suggest_impl(start, limit, incompletes, prefix = '', results = Set.new)
|
27
|
-
if start
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
results =
|
41
|
-
child.suggest_impl(start[1..-1], limit, incompletes, prefix, results)
|
27
|
+
return complete(limit, incompletes, prefix, results) if start.empty?
|
28
|
+
|
29
|
+
child = @children.fetch(start[0]) { Silent.instance }
|
30
|
+
child.suggest_impl(start[1..-1], limit, incompletes, prefix, results)
|
31
|
+
end
|
32
|
+
|
33
|
+
def complete(limit, incompletes, prefix, results)
|
34
|
+
return results if limit != :none && limit < 0
|
35
|
+
add_current_prefix_if_needed(results, limit, incompletes, prefix)
|
36
|
+
limit = next_limit limit
|
37
|
+
return results unless limit == :none || limit >= 0
|
38
|
+
@children.each do |key, child|
|
39
|
+
results = child.complete(limit, incompletes, prefix + key, results)
|
42
40
|
end
|
43
41
|
results
|
44
42
|
end
|
45
43
|
|
44
|
+
def next_limit(limit)
|
45
|
+
return :none if limit == :none
|
46
|
+
limit - 1
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_current_prefix_if_needed(results, limit, incompletes, prefix)
|
50
|
+
results << prefix if @leave || (incompletes && limit == 0)
|
51
|
+
end
|
52
|
+
|
46
53
|
class SuggestParamError < StandardError; end
|
47
54
|
|
48
55
|
NEG_VAL_ERR = 'Strictly non negative values accepted only'
|
data/lib/enf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Ignjatovic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Graph based white/black list implementation. Your elephant won't forget.
|
14
14
|
email: alexandre.ignjatovic@gmail.com
|