middleman-spellcheck 0.6 → 0.7
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3b3f661cc88f7997170682965e91ca43664af24
|
4
|
+
data.tar.gz: fb32f440a6329d79730a939e323ead6c467142dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6541d112edfeb163ee93d51a3678d7d1cafeb0eef2f97cd2b1d349b20fa333ea2ef6c5a935352575294f74d4286126e494b90205fa2cac6c26057722cae2ebec
|
7
|
+
data.tar.gz: 46e9cebbd427446001e4e5a6dd03c683d0f2e7184bd0b58ae297e3a77671c4ee893924f098bad1e82cf13e0a86a8f7237956adfbc7b99ff5ce2560072a0ef3c3
|
@@ -10,22 +10,19 @@ class Spellchecker
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.query(text, lang='en')
|
13
|
-
result = `echo "#{
|
13
|
+
result = `echo "#{text}" | #{@@aspell_path} -a -l #{lang}`
|
14
14
|
raise 'Aspell command not found' unless result
|
15
|
-
result.split("\n")
|
15
|
+
new_result = result.split("\n")
|
16
|
+
new_result[1..-1] || []
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.correct?(result_string)
|
19
20
|
result_string == "*"
|
20
21
|
end
|
21
22
|
|
22
|
-
def self.format_text(text)
|
23
|
-
text.gsub("\n", "")
|
24
|
-
end
|
25
|
-
|
26
23
|
def self.check(text, lang='en')
|
27
|
-
words = text.split(
|
28
|
-
results = query(
|
24
|
+
words = text.split(/[^A-Za-z'\-]+/)
|
25
|
+
results = query(words.join(" "), lang).map do |query_result|
|
29
26
|
correct?(query_result)
|
30
27
|
end
|
31
28
|
|
@@ -26,4 +26,37 @@ describe Spellchecker do
|
|
26
26
|
{ word: "Lucy", correct: true}]
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
context "filtering only words" do
|
31
|
+
let(:text) { "https://something.com is good as 111" }
|
32
|
+
|
33
|
+
it "ignores digits and special characters" do
|
34
|
+
result.should == [{ word: "https", correct: false },
|
35
|
+
{ word: "something", correct: true },
|
36
|
+
{ word: "com", correct: true },
|
37
|
+
{ word: "is", correct: true },
|
38
|
+
{ word: "good", correct: true },
|
39
|
+
{ word: "as", correct: true }]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with apostrophes" do
|
44
|
+
let(:text) { "A user's page" }
|
45
|
+
|
46
|
+
it "whitelists the word" do
|
47
|
+
result.should == [{ word: "A", correct: true },
|
48
|
+
{ word: "user's", correct: true },
|
49
|
+
{ word: "page", correct: true }]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with dashes" do
|
54
|
+
let(:text) { "A user-defined entity" }
|
55
|
+
|
56
|
+
it "whitelists the word" do
|
57
|
+
result.should == [{ word: "A", correct: true },
|
58
|
+
{ word: "user-defined", correct: true },
|
59
|
+
{ word: "entity", correct: true }]
|
60
|
+
end
|
61
|
+
end
|
29
62
|
end
|