Class: Spellcop::FileChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/spellcop/file_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ FileChecker

Returns a new instance of FileChecker.



5
6
7
8
9
# File 'lib/spellcop/file_checker.rb', line 5

def initialize(filename)
  @file = File.read(filename)
  @warnings = []
  @dict = FFI::Hunspell.dict('en_US')
end

Instance Attribute Details

#warningsObject (readonly)

Returns the value of attribute warnings.



3
4
5
# File 'lib/spellcop/file_checker.rb', line 3

def warnings
  @warnings
end

Instance Method Details

#check!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/spellcop/file_checker.rb', line 11

def check!
  comments = @file.scan /#(.*)/
  comments.each do |comment|
    words = comment.first.strip.scan /@(\w+)|\[(\w+)|(\w+)/
    words.each do |result|
      word = result.compact.first
#           puts "wrong: #{word}" if word == 'tihs'
      if !@dict.check? word and !word.spellcop_ignore?
        @warnings << { word: word, suggestions: @dict.suggest(word) }
      end
    end
  end
  @warnings
end