spellchecker 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Spellchecker #:nodoc
2
- VERSION = "0.1"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/spellchecker.rb CHANGED
@@ -4,22 +4,31 @@ class Spellchecker
4
4
  require 'rexml/document'
5
5
 
6
6
  ASPELL_WORD_DATA_REGEX = Regexp.new(/\&\s\w+\s\d+\s\d+(.*)$/)
7
- ASPELL_PATH = "aspell"
7
+ ASPELL_PATH = "/usr/local/bin/aspell"
8
8
 
9
9
  def self.check(text, lang='en')
10
10
  spell_check_response = `echo "#{text}" | #{ASPELL_PATH} -a -l #{lang}`
11
- unless spell_check_response == ''
11
+ if spell_check_response == ''
12
+ raise 'Aspell command not found'
13
+ elsif text == ''
14
+ return []
15
+ else
12
16
  response = text.split(' ').collect { |original| {:original => original} }
13
- spell_check_response.split("\n").slice(1..-1).each_with_index do |error, index|
14
- if match_data = error.match(ASPELL_WORD_DATA_REGEX)
15
- response[index].merge!(:correct => false, :suggestions => error.split(',')[1..-1].collect(&:strip!))
17
+ results = spell_check_response.split("\n").slice(1..-1)
18
+ result_index = 0
19
+ response.each_with_index do |word_hash, index|
20
+ if word_hash[:original] =~ /[a-zA-z]/
21
+ if results[result_index] =~ ASPELL_WORD_DATA_REGEX
22
+ response[index].merge!(:correct => false, :suggestions => results[result_index].split(',')[1..-1].collect(&:strip!))
23
+ else
24
+ response[index].merge!(:correct => true)
25
+ end
26
+ result_index += 1
16
27
  else
17
28
  response[index].merge!(:correct => true)
18
29
  end
19
30
  end
20
31
  return response
21
- else
22
- raise 'Aspell command not found'
23
32
  end
24
33
  end
25
34
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spellchecker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- version: "0.1"
9
+ - 1
10
+ version: 0.1.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - RedBeard Tech
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-12-10 00:00:00 -06:00
18
+ date: 2010-12-13 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies: []
20
21