mindtrick 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mindtrick/set.rb +19 -4
- data/lib/mindtrick/version.rb +1 -1
- data/mindtrick.gemspec +1 -2
- data/test/set_test.rb +7 -1
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bf519df5a41d07c7063de9c5490eec1ad11ebe0
|
4
|
+
data.tar.gz: 6fbb4d0fae1f29f58fc4464fd8bdf340285a8fa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f5f56f093ec7b99c16848afb665e032d6ae8c38e6f8dd231ecf3f43504e4eb0cbaddbd195c16d07294c3d6858ea630b4d0882de7dbb66873000dd18858723fd
|
7
|
+
data.tar.gz: 33fbbaf958389fce555553eaf71c1794da1fbcb4b8524ebde13e503abc272033f74c9ce633e993ba83f8d0fd442646590b0c4da67d49fdbe6b236b1ab27e7e25
|
data/lib/mindtrick/set.rb
CHANGED
@@ -10,15 +10,30 @@ module Mindtrick
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def add(term)
|
13
|
+
fragmentize(term) do |k|
|
14
|
+
redis.zincrby(k, 1, term)
|
15
|
+
enforce_term_limit(k)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def seed(term)
|
20
|
+
fragmentize(term) do |k|
|
21
|
+
unless redis.zscore(k, term)
|
22
|
+
redis.zadd(k, 1, term)
|
23
|
+
enforce_term_limit(k)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def fragmentize(term)
|
13
29
|
term = Text.new(term)
|
14
30
|
term.each_fragment do |f|
|
15
31
|
if f.length <= max_length
|
16
|
-
|
17
|
-
|
18
|
-
|
32
|
+
yield f.prefixed(prefix)
|
33
|
+
else
|
34
|
+
break
|
19
35
|
end
|
20
36
|
end
|
21
|
-
term
|
22
37
|
end
|
23
38
|
|
24
39
|
def suggest(partial, count = 10)
|
data/lib/mindtrick/version.rb
CHANGED
data/mindtrick.gemspec
CHANGED
@@ -18,9 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^test/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency 'redis', '~> 3.0'
|
22
|
-
|
23
21
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
24
22
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'redis', '~> 3.0'
|
25
24
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
26
25
|
end
|
data/test/set_test.rb
CHANGED
@@ -22,12 +22,18 @@ class SetTest < Minitest::Test
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
25
|
def test_add
|
27
26
|
set.add('qux')
|
28
27
|
assert_includes set.suggest('q'), 'qux'
|
29
28
|
end
|
30
29
|
|
30
|
+
def test_seed
|
31
|
+
set.seed('apple')
|
32
|
+
assert_equal 1, redis.zscore("#{ prefix }:a", 'apple')
|
33
|
+
set.seed('apple')
|
34
|
+
assert_equal 1, redis.zscore("#{ prefix }:a", 'apple')
|
35
|
+
end
|
36
|
+
|
31
37
|
def test_suggest
|
32
38
|
build_samples
|
33
39
|
results = set.suggest "foo"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mindtrick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lewis
|
@@ -11,47 +11,47 @@ cert_chain: []
|
|
11
11
|
date: 2014-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
type: :
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: redis
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,4 +114,3 @@ test_files:
|
|
114
114
|
- test/set_test.rb
|
115
115
|
- test/test_helper.rb
|
116
116
|
- test/text_test.rb
|
117
|
-
has_rdoc:
|