Class: Forspell::Reporter
- Inherits:
-
Object
- Object
- Forspell::Reporter
- Defined in:
- lib/forspell/reporter.rb
Constant Summary collapse
- SUCCESS_CODE =
0- ERROR_CODE =
1- DICT_PATH =
File.join(Dir.pwd, 'forspell.dict')
- DICT_OVERWRITE =
'Do you want to overwrite forspell.dict? (yN)'- SUGGEST_FORMAT =
'(suggestions: %<suggestions>s)'- ERROR_FORMAT =
'%<file>s:%<line>i: %<text>s %<suggest>s'- SUMMARY =
"Forspell inspects *.rb, *.c, *.cpp, *.md files\n"\ '%<files>i inspected, %<errors>s detected'
Instance Attribute Summary collapse
-
#progress_bar ⇒ Object
Returns the value of attribute progress_bar.
Instance Method Summary collapse
- #error(word, suggestions) ⇒ Object
- #file(path) ⇒ Object
- #finalize ⇒ Object
-
#initialize(logfile:, verbose:, format:, print_filepaths: false) ⇒ Reporter
constructor
A new instance of Reporter.
- #parsing_error(error) ⇒ Object
- #path_load_error(path) ⇒ Object
- #report ⇒ Object
Constructor Details
#initialize(logfile:, verbose:, format:, print_filepaths: false) ⇒ Reporter
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/forspell/reporter.rb', line 23 def initialize(logfile:, verbose:, format:, print_filepaths: false) FileUtils.touch(logfile) if logfile.is_a?(String) @logger = Logger.new(logfile || STDERR) @logger.level = verbose ? Logger::INFO : Logger::WARN @logger.formatter = proc { |*, msg| "#{msg}\n" } @format = format @pastel = Pastel.new(enabled: $stdout.tty?) @errors = [] @files = [] @print_filepaths = print_filepaths end |
Instance Attribute Details
#progress_bar ⇒ Object
Returns the value of attribute progress_bar.
21 22 23 |
# File 'lib/forspell/reporter.rb', line 21 def end |
Instance Method Details
#error(word, suggestions) ⇒ Object
45 46 47 48 |
# File 'lib/forspell/reporter.rb', line 45 def error(word, suggestions) @errors << [word, suggestions] print(readable(word, suggestions)) if @format == 'readable' end |
#file(path) ⇒ Object
40 41 42 43 |
# File 'lib/forspell/reporter.rb', line 40 def file(path) @logger.info "Processing #{path}" @files << path end |
#finalize ⇒ Object
69 70 71 |
# File 'lib/forspell/reporter.rb', line 69 def finalize @errors.empty? ? SUCCESS_CODE : ERROR_CODE end |
#parsing_error(error) ⇒ Object
50 51 52 |
# File 'lib/forspell/reporter.rb', line 50 def parsing_error(error) @logger.error "Parsing error in #{@files.last}: #{error}" end |
#path_load_error(path) ⇒ Object
54 55 56 |
# File 'lib/forspell/reporter.rb', line 54 def path_load_error path @logger.error "Path not found: #{path}" end |
#report ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/forspell/reporter.rb', line 58 def report case @format when 'readable' print_summary when 'dictionary' print_dictionary when 'json', 'yaml' print_formatted end end |