Class: TypoChecker::FileScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/typo_checker/file_scanner.rb

Instance Method Summary collapse

Constructor Details

#initialize(typos, stdoutput) ⇒ FileScanner

Returns a new instance of FileScanner.



3
4
5
6
# File 'lib/typo_checker/file_scanner.rb', line 3

def initialize(typos, stdoutput)
  @typos = typos
  @stdoutput = stdoutput
end

Instance Method Details

#scan_file(path, result) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/typo_checker/file_scanner.rb', line 8

def scan_file(path, result)
  File.foreach(path).with_index do |line, line_number|
    words = line.split(/[^a-zA-Z0-9']+/)
    check_words = words.map { |word| split_function_name(word) }.flatten
    check_words.each do |word|
      clean_word = word.gsub(/^[^\w]+|[^\w]+$/, '')
      char_index = line.index(clean_word)
      check_word(clean_word, path, line_number, char_index, result)
    end
  end
end