Class: Collie::Reporter::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/collie/reporter/text.rb

Overview

Text reporter for terminal output

Instance Method Summary collapse

Constructor Details

#initialize(colorize: true) ⇒ Text

Returns a new instance of Text.



14
15
16
17
# File 'lib/collie/reporter/text.rb', line 14

def initialize(colorize: true)
  @colorize = colorize && PASTEL_AVAILABLE
  @pastel = PASTEL_AVAILABLE ? Pastel.new(enabled: @colorize) : nil
end

Instance Method Details

#report(offenses) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/collie/reporter/text.rb', line 19

def report(offenses)
  return success_message if offenses.empty?

  grouped = offenses.group_by { |o| o.location.file }
  output = []

  grouped.each do |file, file_offenses|
    output << ""
    output << (@pastel ? @pastel.bold(file) : file)

    file_offenses.sort_by { |o| [o.location.line, o.location.column] }.each do |offense|
      output << format_offense(offense)
    end
  end

  output << ""
  output << summary(offenses)
  output.join("\n")
end