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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35514c456a9f75e1cde8529243ede1c9c04281db
4
- data.tar.gz: 2f8d34721606d5abdc48804ca87137e2a40fd835
3
+ metadata.gz: 1bf519df5a41d07c7063de9c5490eec1ad11ebe0
4
+ data.tar.gz: 6fbb4d0fae1f29f58fc4464fd8bdf340285a8fa0
5
5
  SHA512:
6
- metadata.gz: 5ba82350e58c9bfa47dd2131bc225c19d566fbaeef87664f2b4b41cf3d9ccee46075b5b7827a4a62c0e000a09aae241c423a2b64f5e2e360ade54a44da0bed0d
7
- data.tar.gz: 50289e71b97fb2f349481f5daf0ab78ab3db5ee3e2d2d1b1fa191dc3359f5a43dcfcea067a3f11b2458a477cf3e74e7185f0200809ac3cc829049b33c343f41a
6
+ metadata.gz: 6f5f56f093ec7b99c16848afb665e032d6ae8c38e6f8dd231ecf3f43504e4eb0cbaddbd195c16d07294c3d6858ea630b4d0882de7dbb66873000dd18858723fd
7
+ data.tar.gz: 33fbbaf958389fce555553eaf71c1794da1fbcb4b8524ebde13e503abc272033f74c9ce633e993ba83f8d0fd442646590b0c4da67d49fdbe6b236b1ab27e7e25
@@ -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
- k = f.prefixed(prefix)
17
- redis.zincrby(k, 1, term)
18
- enforce_term_limit(k)
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)
@@ -1,3 +1,3 @@
1
1
  module Mindtrick
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
@@ -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.2
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: redis
14
+ name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
20
- type: :runtime
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: '3.0'
26
+ version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.6'
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: '1.6'
40
+ version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: redis
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
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: '10.0'
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: