ru_bee 0.0.8 → 0.0.9

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.
@@ -1,3 +1,3 @@
1
1
  module RuBee
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/lib/suggestion.rb CHANGED
@@ -10,34 +10,51 @@ class Suggestion
10
10
  end
11
11
 
12
12
  def suggestions
13
- result = try_1
14
- if result.count < 1
15
- result = try_2
16
- if try_2.count > 0
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 try_1
24
- find(@word) | find(@word[0...-1]) | find(@word[0...-2])
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 try_2
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
- @dictionary.join("\n").scan(/(.*[#{@word}]+.*)/).flatten
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
@@ -7,7 +7,7 @@ describe Dictionary do
7
7
  describe '#contents' do
8
8
 
9
9
  it 'should have x amount contents' do
10
- expect(dictionary.contents.count).to eq(235887)
10
+ expect(dictionary.contents.count).to eq(261473)
11
11
  end
12
12
 
13
13
  end
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
@@ -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.8
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-21 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler