class Spellcop::FileChecker

Attributes

warnings[R]

Public Class Methods

new(filename) click to toggle source
# File lib/spellcop/file_checker.rb, line 5
def initialize(filename)
  @file = File.read(filename)
  @warnings = []
  @dict = FFI::Hunspell.dict('en_US')
end

Public Instance Methods

check!() click to toggle source
# 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