Sha256: 137fd77cb5602895060b393981534626c399a055fae4a2db31c4e4d3ff8bcd85

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'pluginscan/printer'

module Pluginscan
  class CLOCPrinter < Printer
    def print(cloc)
      print_headline
      print_results(cloc)
      print_blank_line
    end

  private

    def print_headline
      @output.puts "SLOC counts from the 'CLOC' tool:".color(:blue)
    end

    def print_results(cloc)
      print_no_result if cloc.language_counts.empty?

      cloc.language_counts.each{ |language_count| print_result language_count }
    end

    def print_result(language_count)
      data = {
        language:   language_count.language.color(:green),
        sloc:       language_count.sloc.to_s.color(:red),
        file_count: language_count.file_count,
      }
      # Field widths need to account for the colouring characters: 9 of them in total
      # e.g. for red this is \e[31m at the beginning and \e[0m at the end,
      # with \e counting as one character:
      #   pad sloc     to 5  (+9 = 14)
      #   pad language to 12 (+9 = 21)
      @output.puts format("  %<language>-21s %<sloc>14s lines across %<file_count>2d files\n", data)
    end

    def print_no_result
      sadface = ":(".color(:red)
      @output.puts "  CLOC didn't find any code #{sadface}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pluginscan-0.9.0 lib/pluginscan/reports/cloc_report/cloc_printer.rb