class YardJunk::Janitor::BaseReporter
This class is a base for reporters that could be passed to {Janitor#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”).
Public Class Methods
new(io_or_filename = $stdout)
click to toggle source
@overload initialize(io)
@param io [#puts] Any IO-alike object that defines `puts` method.
@overload initialize(filename)
@param filename [String] Name of file to save the output.
# 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
Public Instance Methods
finalize()
click to toggle source
# File lib/yard-junk/janitor/base_reporter.rb, line 34 def finalize; end
section(title, explanation, messages)
click to toggle source
# File lib/yard-junk/janitor/base_reporter.rb, line 36 def section(title, explanation, messages) return if messages.empty? header(title, explanation) messages .sort_by { |m| [m.file || '\uFFFF', m.line || 1000, m.message] } .each(&method(:row)) end
stats(**stat)
click to toggle source
# File lib/yard-junk/janitor/base_reporter.rb, line 46 def stats(**stat) _stats(**stat.merge(duration: humanize_duration(stat[:duration]))) end
Private Instance Methods
_stats()
click to toggle source
# File lib/yard-junk/janitor/base_reporter.rb, line 52 def _stats fail NotImplementedError end
header(_title, _explanation)
click to toggle source
# File lib/yard-junk/janitor/base_reporter.rb, line 56 def header(_title, _explanation) fail NotImplementedError end
humanize_duration(duration)
click to toggle source
# File lib/yard-junk/janitor/base_reporter.rb, line 64 def humanize_duration(duration) if duration < 60 '%i seconds' % duration else '%.1f minutes' % (duration / 60) end end
row(_message)
click to toggle source
# File lib/yard-junk/janitor/base_reporter.rb, line 60 def row(_message) fail NotImplementedError end