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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fe4cc422bed7680506a19566446cf892a7a4f2b
4
- data.tar.gz: 0032fa20fdc2ef7ac2343bc1587f3f749f8aa764
3
+ metadata.gz: 3aa05a4afb0adf081ecd35a98ddadf81357da91a
4
+ data.tar.gz: db6ccc6c863db56f53d83f1ac43a1d51bf73a034
5
5
  SHA512:
6
- metadata.gz: ba6d389d65cd195790b14bab10fc01af33e9b147046b38a40b3528bd5aeb44efba50bc2492fdfc010200bf97169f81bfd16874333395aeb4023a9d9823095b55
7
- data.tar.gz: 65f92d19a83ff8fc5a46543e7847e5596c10933910a660b0fccf39ae79bdbfe76550d3ca4e0252a8d0b5566d36343c5b5669484e5a18511e258a41bd9f7e9f19
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
- return results if limit != :none && limit < 0
29
- results << prefix if @leave || (incompletes && limit == 0)
30
- limit = limit - 1 unless limit == :none
31
- if limit == :none || limit >= 0
32
- @children.each do |key, child|
33
- new_prefix = prefix + key
34
- results =
35
- child.suggest_impl(start, limit, incompletes, new_prefix, results)
36
- end
37
- end
38
- else
39
- child = @children.fetch(start[0]) { Silent.instance }
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
@@ -3,7 +3,7 @@
3
3
  module Enf
4
4
  # This module holds the Enf version information.
5
5
  module Version
6
- STRING = '0.1.0'
6
+ STRING = '0.1.1'
7
7
 
8
8
  module_function
9
9
 
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.0
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-16 00:00:00.000000000 Z
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