Class: YardJunk::Janitor::BaseReporter
- Inherits:
-
Object
- Object
- YardJunk::Janitor::BaseReporter
- Defined in:
- lib/yard-junk/janitor/base_reporter.rb
Overview
This class is a base for reporters that could be passed to #report.
Basically, the reporter should define methods:
-
‘header(title, explanation)` for printing problems section header;
-
‘row(msg)` for printing instance of Logger::Message;
-
‘_stats(**statistics)` for printing statistics.
Reporter also could redefine ‘finalize()` method, if it wants to do something at the end of a report (like “add footer and save to file”).
Direct Known Subclasses
Instance Method Summary collapse
- #finalize ⇒ Object
-
#initialize(io_or_filename = $stdout) ⇒ BaseReporter
constructor
A new instance of BaseReporter.
- #section(title, explanation, messages) ⇒ Object
- #stats(**stat) ⇒ Object
Constructor Details
#initialize(io) ⇒ BaseReporter #initialize(filename) ⇒ BaseReporter
Returns a new instance of BaseReporter.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/yard-junk/janitor/base_reporter.rb', line 22 def initialize(io_or_filename = $stdout) @io = case io_or_filename when ->(i) { i.respond_to?(:puts) } # quacks! io_or_filename when String File.open(io_or_filename, 'w') else fail ArgumentError, "Can't create reporter with #{io_or_filename.class}" end end |
Instance Method Details
#finalize ⇒ Object
34 |
# File 'lib/yard-junk/janitor/base_reporter.rb', line 34 def finalize; end |
#section(title, explanation, messages) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/yard-junk/janitor/base_reporter.rb', line 36 def section(title, explanation, ) return if .empty? header(title, explanation) .sort_by { |m| [m.file || '\uFFFF', m.line || 1000, m.] } .each(&method(:row)) end |
#stats(**stat) ⇒ Object
46 47 48 |
# File 'lib/yard-junk/janitor/base_reporter.rb', line 46 def stats(**stat) _stats(**stat.merge(duration: humanize_duration(stat[:duration]))) end |