ru_bee 0.0.6 → 0.0.7
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 +8 -8
- data/lib/ru_bee/version.rb +1 -1
- data/lib/scanner.rb +7 -4
- data/lib/suggestion.rb +46 -0
- data/spec/scanner_spec.rb +7 -0
- data/spec/suggestion_spec.rb +61 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmQyNTg0NWQ5NDM0OWZjYjJmZTk1ZTc0MzA0MTE5YTVlMWYyNzExYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTVhNDE2MjY4MDU4MzkwMWE0NDJhNDdiZWY1N2FkZjUwODUyYjUxMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Nzk4ZDk1YWI4MDAwNTYzOGQ1OGRhNGYyNjJiNDJlZGQ0ZThiZmM5M2M1MDZi
|
10
|
+
M2ZiMzJmMTM5ODIzNTUxNzQwZmM1MzExNzcwYzMyOTJjYzRjOGE3MjlkZTNk
|
11
|
+
ZTVlYjBlMmVhMzUxMDAyOGE3YTQ5YmFhNTUyMjVjYTdmOWQxODY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZWZmZDMyNjcyMDkyZWFhMDY4MjQyZGQwMTgxMWZjZTRjNjc5MDQwOWM5ZDQy
|
14
|
+
YmY1NjFlYmNiYzU4OGU5N2ExY2U0ZmZhODNhNWU4NzVkZjczMjJhMTlhZGQw
|
15
|
+
ZGMzNDFjM2U1N2UwMDMxYjJjMjM4OGMzYmMyZWY0ODljODlhYjY=
|
data/lib/ru_bee/version.rb
CHANGED
data/lib/scanner.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'suggestion'
|
2
|
+
|
1
3
|
class String
|
2
4
|
|
3
5
|
def correct? options={}
|
@@ -7,7 +9,7 @@ class String
|
|
7
9
|
|
8
10
|
def misspellings options={}
|
9
11
|
@options = options
|
10
|
-
check true
|
12
|
+
check({collect: true, suggestions: @options[:suggestions]})
|
11
13
|
@bad_words
|
12
14
|
end
|
13
15
|
|
@@ -56,7 +58,7 @@ class String
|
|
56
58
|
word
|
57
59
|
end
|
58
60
|
|
59
|
-
def check
|
61
|
+
def check opts={}
|
60
62
|
@bad_words = []
|
61
63
|
words.each do |word|
|
62
64
|
unless dictionary.include?("#{word}") or
|
@@ -64,8 +66,9 @@ class String
|
|
64
66
|
dictionary.include?("#{remove_ed(word)}") or
|
65
67
|
dictionary.include?("#{remove_ing(word)}") or
|
66
68
|
dictionary.include?("#{remove_es(word)}")
|
67
|
-
|
68
|
-
|
69
|
+
suggestion = Suggestion.new word, @dictionary
|
70
|
+
@bad_words << (opts[:suggestions] ? suggestion.search : word)
|
71
|
+
return false unless opts[:collect]
|
69
72
|
end
|
70
73
|
end
|
71
74
|
true
|
data/lib/suggestion.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
class Suggestion
|
2
|
+
|
3
|
+
def initialize word, dictionary
|
4
|
+
@word = word
|
5
|
+
@dictionary = dictionary
|
6
|
+
end
|
7
|
+
|
8
|
+
def search
|
9
|
+
format suggestions.take(50)
|
10
|
+
end
|
11
|
+
|
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
|
19
|
+
end
|
20
|
+
result
|
21
|
+
end
|
22
|
+
|
23
|
+
def try_1
|
24
|
+
find(@word) | find(@word[0...-1]) | find(@word[0...-2])
|
25
|
+
end
|
26
|
+
|
27
|
+
def try_2
|
28
|
+
find(@word.reverse[0...-1].reverse) |
|
29
|
+
find(@word.reverse[0...-2].reverse) |
|
30
|
+
find(@word.reverse[0...-3].reverse)
|
31
|
+
end
|
32
|
+
|
33
|
+
def try_3
|
34
|
+
parts = @word.chars.to_a.join('')
|
35
|
+
@dictionary.join("\n").scan(/(.*[#{parts}]+.*)/).flatten
|
36
|
+
end
|
37
|
+
|
38
|
+
def find word
|
39
|
+
@dictionary.join("\n").scan(/(.*#{word}.*)/).flatten
|
40
|
+
end
|
41
|
+
|
42
|
+
def format sug_arr
|
43
|
+
{word: @word, suggestions: sug_arr}
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/spec/scanner_spec.rb
CHANGED
@@ -32,6 +32,13 @@ describe String do
|
|
32
32
|
expect(test_string_good.misspellings.count).to eq(0)
|
33
33
|
end
|
34
34
|
|
35
|
+
it 'should return suggestions if optioned' do
|
36
|
+
suggestions = test_string_bad.misspellings(suggestions: true)
|
37
|
+
expect(suggestions[0][:suggestions]).to eq([])
|
38
|
+
answer = %w{berger brauneberger coberger johannisberger scharlachberger steinberger weinbergerite habergeon hauberget ramberge}
|
39
|
+
expect(suggestions[1][:suggestions]).to eq(answer)
|
40
|
+
end
|
41
|
+
|
35
42
|
end
|
36
43
|
|
37
44
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'scanner'
|
2
|
+
|
3
|
+
describe Suggestion do
|
4
|
+
|
5
|
+
let(:suggestion) { Suggestion.new 'test', ["car", "dog", "tester", "dan", "testit"] }
|
6
|
+
|
7
|
+
|
8
|
+
describe '#search' do
|
9
|
+
|
10
|
+
it 'should return hash with word' do
|
11
|
+
expect(suggestion.search[:word]).to eq('test')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should return hash with suggestions array' do
|
15
|
+
expect(suggestion.search[:suggestions][0]).to eq('tester')
|
16
|
+
expect(suggestion.search[:suggestions][1]).to eq('testit')
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#format' do
|
22
|
+
|
23
|
+
it 'should return hash with word' do
|
24
|
+
expect(suggestion.format([['tester'], ['here']])[:word]).to eq('test')
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#suggestions' do
|
30
|
+
|
31
|
+
it 'should return 2 results' do
|
32
|
+
expect(suggestion.suggestions).to eq(['tester', 'testit'])
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#try_1' do
|
38
|
+
|
39
|
+
it 'should return 2 results' do
|
40
|
+
expect(suggestion.try_1).to eq(['tester', 'testit'])
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#try_2' do
|
46
|
+
|
47
|
+
it 'should return 2 results' do
|
48
|
+
expect(suggestion.try_2).to eq(['tester', 'testit'])
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#try_3' do
|
54
|
+
|
55
|
+
it 'should return 2 results' do
|
56
|
+
expect(suggestion.try_3).to eq(['tester', 'testit'])
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
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.7
|
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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,10 +68,12 @@ files:
|
|
68
68
|
- lib/ru_bee.rb
|
69
69
|
- lib/ru_bee/version.rb
|
70
70
|
- lib/scanner.rb
|
71
|
+
- lib/suggestion.rb
|
71
72
|
- ru_bee-0.0.2.gem
|
72
73
|
- ru_bee.gemspec
|
73
74
|
- ru_bee_string.rb
|
74
75
|
- spec/scanner_spec.rb
|
76
|
+
- spec/suggestion_spec.rb
|
75
77
|
homepage: ''
|
76
78
|
licenses:
|
77
79
|
- MIT
|
@@ -98,3 +100,4 @@ specification_version: 4
|
|
98
100
|
summary: Dictionary for Ruby String.
|
99
101
|
test_files:
|
100
102
|
- spec/scanner_spec.rb
|
103
|
+
- spec/suggestion_spec.rb
|