ru_bee 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/dictionaries/english +25589 -3
- data/lib/ru_bee/version.rb +1 -1
- data/lib/suggestion.rb +28 -11
- data/spec/dictionary_spec.rb +1 -1
- data/spec/scanner_spec.rb +0 -1
- data/spec/suggestion_spec.rb +39 -3
- metadata +2 -2
data/lib/ru_bee/version.rb
CHANGED
data/lib/suggestion.rb
CHANGED
@@ -10,34 +10,51 @@ class Suggestion
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def suggestions
|
13
|
-
result =
|
14
|
-
|
15
|
-
result =
|
16
|
-
if
|
17
|
-
result = try_3
|
18
|
-
end
|
13
|
+
result = []
|
14
|
+
(0...5).each do |num|
|
15
|
+
result = self.send("try_#{num}", result)
|
16
|
+
break if result.count > 5
|
19
17
|
end
|
20
18
|
result
|
21
19
|
end
|
22
20
|
|
23
|
-
def
|
24
|
-
|
21
|
+
def try_0 result
|
22
|
+
result | find_by_exp(/(^#{@word}.*)/) |
|
23
|
+
find_by_exp(/(^#{@word[0...-1]}.*)/) |
|
24
|
+
find_by_exp(/(^#{@word[0...-2]}.*)/)
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def try_1 result
|
28
|
+
result | find(@word) | find(@word[0...-1]) | find(@word[0...-2])
|
29
|
+
end
|
30
|
+
|
31
|
+
def try_2 result
|
32
|
+
result |
|
28
33
|
find(@word.reverse[0...-1].reverse) |
|
29
34
|
find(@word.reverse[0...-2].reverse) |
|
30
35
|
find(@word.reverse[0...-3].reverse)
|
31
36
|
end
|
32
37
|
|
33
|
-
def try_3
|
34
|
-
|
38
|
+
def try_3 result
|
39
|
+
result | find_by_exp(/(.*#{@word[0...3]}.*?[#{@word[0...-3]}]+.*)/)
|
40
|
+
end
|
41
|
+
|
42
|
+
def try_4 result
|
43
|
+
result | find_by_exp(/(.*[#{@word[0...3]}].*?#{@word[0...-3]}+.*)/)
|
44
|
+
end
|
45
|
+
|
46
|
+
def try_5 result
|
47
|
+
result | find_by_exp(/(.*[#{@word}]+.*)/)
|
35
48
|
end
|
36
49
|
|
37
50
|
def find word
|
38
51
|
@dictionary.join("\n").scan(/(.*#{word}.*)/).flatten
|
39
52
|
end
|
40
53
|
|
54
|
+
def find_by_exp exp
|
55
|
+
@dictionary.join("\n").scan(exp).flatten
|
56
|
+
end
|
57
|
+
|
41
58
|
def format sug_arr
|
42
59
|
{word: @word, suggestions: sug_arr}
|
43
60
|
end
|
data/spec/dictionary_spec.rb
CHANGED
data/spec/scanner_spec.rb
CHANGED
@@ -34,7 +34,6 @@ describe String do
|
|
34
34
|
|
35
35
|
it 'should return suggestions if optioned' do
|
36
36
|
suggestions = test_string_bad.misspellings(suggestions: true)
|
37
|
-
expect(suggestions[0][:suggestions]).to eq([])
|
38
37
|
answer = %w{berger brauneberger coberger johannisberger scharlachberger steinberger weinbergerite habergeon hauberget ramberge}
|
39
38
|
expect(suggestions[1][:suggestions]).to eq(answer)
|
40
39
|
end
|
data/spec/suggestion_spec.rb
CHANGED
@@ -37,7 +37,11 @@ describe Suggestion do
|
|
37
37
|
describe '#try_1' do
|
38
38
|
|
39
39
|
it 'should return 2 results' do
|
40
|
-
expect(suggestion.try_1).to eq(['tester', 'testit'])
|
40
|
+
expect(suggestion.try_1([])).to eq(['tester', 'testit'])
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should carry over results' do
|
44
|
+
expect(suggestion.try_1(['carryover'])).to eq(['carryover', 'tester', 'testit'])
|
41
45
|
end
|
42
46
|
|
43
47
|
end
|
@@ -45,7 +49,11 @@ describe Suggestion do
|
|
45
49
|
describe '#try_2' do
|
46
50
|
|
47
51
|
it 'should return 2 results' do
|
48
|
-
expect(suggestion.try_2).to eq(['tester', 'testit'])
|
52
|
+
expect(suggestion.try_2([])).to eq(['tester', 'testit'])
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should carry over results' do
|
56
|
+
expect(suggestion.try_2(['carryover'])).to eq(['carryover', 'tester', 'testit'])
|
49
57
|
end
|
50
58
|
|
51
59
|
end
|
@@ -53,7 +61,35 @@ describe Suggestion do
|
|
53
61
|
describe '#try_3' do
|
54
62
|
|
55
63
|
it 'should return 2 results' do
|
56
|
-
expect(suggestion.try_3).to eq(['tester', 'testit'])
|
64
|
+
expect(suggestion.try_3([])).to eq(['tester', 'testit'])
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should carry over results' do
|
68
|
+
expect(suggestion.try_3(['carryover'])).to eq(['carryover', 'tester', 'testit'])
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#try_4' do
|
74
|
+
|
75
|
+
it 'should return 2 results' do
|
76
|
+
expect(suggestion.try_4([])).to eq(['tester', 'testit'])
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should carry over results' do
|
80
|
+
expect(suggestion.try_4(['carryover'])).to eq(['carryover', 'tester', 'testit'])
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#try_5' do
|
86
|
+
|
87
|
+
it 'should return 2 results' do
|
88
|
+
expect(suggestion.try_5([])).to eq(['tester', 'testit'])
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should carry over results' do
|
92
|
+
expect(suggestion.try_5(['carryover'])).to eq(['carryover', 'tester', 'testit'])
|
57
93
|
end
|
58
94
|
|
59
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ru_bee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|