class Forspell::Runner

Public Class Methods

new(files:, speller:, reporter:) click to toggle source
# File lib/forspell/runner.rb, line 6
def initialize(files:, speller:, reporter:)
  @files = files
  @speller = speller
  @reporter = reporter
end

Public Instance Methods

call() click to toggle source
# File lib/forspell/runner.rb, line 12
def call
  increment = (@files.size / 100.0).ceil
  total = @files.size <= 100 ? @files.size : 100
  @reporter.progress_bar = ProgressBar.create(total: total, output: $stderr)

  @files.each_with_index do |path, index|
    process_file path
    @reporter.progress_bar.increment if (index + 1) % increment == 0
  end

  @reporter.report

  self
end

Private Instance Methods

process_file(path) click to toggle source
# File lib/forspell/runner.rb, line 29
def process_file path
  @reporter.file(path) 
  
  words = Loaders.for(path).read
  words.reject { |word| @speller.correct?(word.text) }
       .each { |word| @reporter.error(word, @speller.suggest(word.text)) }
  
rescue Forspell::Loaders::ParsingError => e
  @reporter.parsing_error(e) and return
end