class Chutney::PieFormatter

format results as pie charts

Public Instance Methods

char_loop() click to toggle source
# File lib/chutney/formatter/pie_formatter.rb, line 38
def char_loop
  @char_looper ||= Fiber.new do
    chars = %w[• x + @ * / -]
    current = 0
    loop do
      current = 0 if current >= chars.count
      Fiber.yield chars[current]
      current += 1
    end
  end
  @char_looper.resume
end
colour_loop() click to toggle source
# File lib/chutney/formatter/pie_formatter.rb, line 51
def colour_loop
  @colour_looper ||= Fiber.new do
    colours = %i[bright_cyan bright_magenta bright_yellow bright_green]
    current = 0
    loop do
      current = 0 if current >= colours.count
      Fiber.yield colours[current]
      current += 1
    end
  end
  @colour_looper.resume
end
format() click to toggle source
# File lib/chutney/formatter/pie_formatter.rb, line 9
def format
  data = top_offences.map do |offence|
    {
      name: offence.first,
      value: offence.last,
      color: colour_loop,
      fill: char_loop
    }
  end
  print_report(data)
end
print_report(data) click to toggle source
put_summary() click to toggle source
# File lib/chutney/formatter/pie_formatter.rb, line 64
def put_summary
  pastel = Pastel.new
  print "#{files.count} features inspected, "
  if files_with_issues.count.zero?
    puts pastel.green('all taste delicious')
  else
    puts pastel.red("#{files_with_issues.count} taste nasty")
  end
end
top_offences() click to toggle source
# File lib/chutney/formatter/pie_formatter.rb, line 28
def top_offences
  offence = Hash.new(0)
  files_with_issues.each do |_file, linter|
    linter.each do |lint|
      offence[lint[:linter]] += lint[:issues].count
    end
  end
  offence.reject { |_k, v| v.zero? }.sort_by { |_linter, count| -count }
end