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: f583af567927055546ed6b90a526a32f7dd5da52
4
- data.tar.gz: de8929bfe29e132208fdea35a3eaec7dbb141fa5
3
+ metadata.gz: c3b3f661cc88f7997170682965e91ca43664af24
4
+ data.tar.gz: fb32f440a6329d79730a939e323ead6c467142dd
5
5
  SHA512:
6
- metadata.gz: 52273fd663fed6722d2f711bfc712cc926ac46bfe25495438e65841fbb6668811e3b865c68355f4e3d3876fa91e458baf50f7867d0413099dac6c4dcf21fb5a1
7
- data.tar.gz: 67ed22641c257e5904f58d9a06aa6d63312d0f2a7833af7b583a7d789c49708438295aaaaeb5ab6929e7954e16c30233f0664a5e83ec24c04abf651e9d5e9e98
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 "#{format_text(text)}" | #{@@aspell_path} -a -l #{lang}`
13
+ result = `echo "#{text}" | #{@@aspell_path} -a -l #{lang}`
14
14
  raise 'Aspell command not found' unless result
15
- result.split("\n")[1..-1] || []
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(/\W+/)
28
- results = query(text, lang).map do |query_result|
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
 
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Spellcheck
3
- VERSION = "0.6"
3
+ VERSION = "0.7"
4
4
  end
5
5
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-spellcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.6'
4
+ version: '0.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Zarea