Class: CodeStats::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/code_stats/printer.rb

Instance Method Summary collapse

Constructor Details

#initialize(report) ⇒ Printer

Returns a new instance of Printer.



6
7
8
# File 'lib/code_stats/printer.rb', line 6

def initialize(report)
  @report = report
end

Instance Method Details



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/code_stats/printer.rb', line 10

def print
  @report.each do |dir, depth_reports|
    puts "========== #{dir}"
    (1...depth_reports.size).each do |depth|
      puts "Depth #{depth}"
      puts ""
      depth_reports[depth].each do |dir, report|
        report(dir, report)
      end
    end
    puts ""
    puts 'Summary'.bright
    report('', depth_reports[0].values.first)
  end
end

#report(label, report) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/code_stats/printer.rb', line 26

def report(label, report)
  puts "%-60s %10s %10s" % [label, report.lines, "Lines".color(:red)]
  puts "%-60s %10s %10s" % ['', report.code, "Code".color(:blue)]
  puts "%-60s %10s %10s" % ['', report.comments, "Comments".color(:green)]
  puts "%-60s %10.2f %10s" % ['', report.comments.to_f / report.code, "Comments to code %"] unless report.code.zero?
  puts "%-60s %10s %10s" % ['', report.empty, "Empty".color(:magenta)]
end