ru_bee 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/ru_bee/version.rb +1 -1
- data/lib/scanner.rb +18 -23
- data/spec/scanner_spec.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGIyZDUwMDRjNjA4ZDYwYmZlNjBmNDU5NjY5YWQzMWJmZGE1ZGI3Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWI5MWVjYTA3ODBjNWMyYTIwYjEwNDYwNWYxYzQyYjY1MzI4ZTM0Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTkwOTFjYjZjNjI1MGUwMWQ1MzcwZmQ2OTQ3Yjg3OGJhZTQ4MTNhOTFlODY2
|
10
|
+
MTIyOWI1NzY1NjIxYThkOWRkNjgzMzBiNDQyOWNiMDg0NTY2OTRlOTkyMWE4
|
11
|
+
ZjhjNzUzMzcyZjQzMmQzZGMwOGZjYTcwMWRlZDJhZTFiZmQ2MGM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmYxODVjYzFiZGM2NWFjYzI5ZmM4NTk1ZGRhYmE5Nzk0YzNiMGM0NDVkNjdh
|
14
|
+
NzZmNDljMTllOGQzN2U3NzJkOWI1MjRmNTFhNTMxMWEyOWMxYWQ3OWZiNjc5
|
15
|
+
OTgzYjIxM2EzYjY2ZDI1ZmMxODg1Yzc4ZjVlMmY5MDBiMjA5ODM=
|
data/lib/ru_bee/version.rb
CHANGED
data/lib/scanner.rb
CHANGED
@@ -1,36 +1,31 @@
|
|
1
1
|
class String
|
2
2
|
|
3
|
-
@dictionary = []
|
4
|
-
@options = {}
|
5
|
-
|
6
3
|
def correct? options={}
|
7
4
|
@options = options
|
8
|
-
get_parts
|
9
|
-
load_dictionary
|
10
5
|
check
|
11
6
|
end
|
12
7
|
|
13
8
|
def misspellings options={}
|
14
9
|
@options = options
|
15
|
-
get_parts
|
16
|
-
load_dictionary
|
17
10
|
check true
|
18
11
|
@bad_words
|
19
12
|
end
|
20
13
|
|
21
14
|
private
|
22
15
|
|
23
|
-
def
|
24
|
-
@
|
16
|
+
def words
|
17
|
+
@words ||= self.downcase.gsub(/[\'\"]/, '').scan(/[a-z]+/)
|
25
18
|
end
|
26
19
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
20
|
+
def dictionary
|
21
|
+
@dictionary ||= begin
|
22
|
+
filename = @options[:language] || 'english'
|
23
|
+
path = File.dirname(__FILE__)
|
24
|
+
file = File.open("#{path}/dictionaries/#{filename}", "r")
|
25
|
+
contents = file.read.downcase.split(/\n/)
|
26
|
+
file.close
|
27
|
+
contents || []
|
28
|
+
end
|
34
29
|
end
|
35
30
|
|
36
31
|
def remove_s word
|
@@ -63,16 +58,16 @@ class String
|
|
63
58
|
|
64
59
|
def check collect=false
|
65
60
|
@bad_words = []
|
66
|
-
|
67
|
-
unless
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
61
|
+
words.each do |word|
|
62
|
+
unless dictionary.include?("#{word}") or
|
63
|
+
dictionary.include?("#{remove_s(word)}") or
|
64
|
+
dictionary.include?("#{remove_ed(word)}") or
|
65
|
+
dictionary.include?("#{remove_ing(word)}") or
|
66
|
+
dictionary.include?("#{remove_es(word)}")
|
72
67
|
@bad_words << word
|
73
68
|
return false unless collect
|
74
69
|
end
|
75
|
-
end
|
70
|
+
end
|
76
71
|
true
|
77
72
|
end
|
78
73
|
|
data/spec/scanner_spec.rb
CHANGED
@@ -35,10 +35,10 @@ describe String do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
|
38
|
-
describe '#
|
38
|
+
describe '#words' do
|
39
39
|
|
40
40
|
it 'should break string into word parts' do
|
41
|
-
expect(test_string_good.send('
|
41
|
+
expect(test_string_good.send('words').count).to eq(10)
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
@@ -47,7 +47,7 @@ describe String do
|
|
47
47
|
|
48
48
|
it 'should set DICTIONARY to' do
|
49
49
|
test_string_good.correct?
|
50
|
-
expect(test_string_good.send('
|
50
|
+
expect(test_string_good.send('dictionary').count).to eq(235887)
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|