6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/rspec_let_analyzer/formatters/ascii_formatter.rb', line 6
def format(analyzer:, limit:, sort_by:)
sorted = analyzer.top(limit, sort_by)
totals = analyzer.totals
total_files = analyzer.results.size
nesting_depth = analyzer.nesting_depth
base_width = 60
col_width = 10
output = []
num_cols = 5 + (nesting_depth || 0)
separator = "+#{(['-' * base_width] + (['-' * col_width] * num_cols)).join('+')}+"
output << separator
= ['File', 'Total', 'Root', 'it blocks']
if nesting_depth
(1...nesting_depth).each { |i| << "Nest #{i}" }
<< "Nest #{nesting_depth}+"
end
<< 'Redef'
<< 'Bef Cr'
= "| %-58s |#{' %8s |' * (headers.size - 1)}"
output << ( % )
output << separator
sorted.each do |result|
file_display = result[:file].size > 58 ? "...#{result[:file][-55..]}" : result[:file]
values = [file_display, result[:total_score], result[:root_lets], result[:it_blocks]]
nesting_depth&.times do |i|
values << result[:"nesting_#{i + 1}"]
end
values << result[:redefinitions]
values << result[:before_creates]
row_format = "| %-58s |#{' %8d |' * (values.size - 1)}"
output << (row_format % values)
end
output << separator
total_values = ["TOTAL (all #{total_files} files)", totals[:total_score], totals[:root_lets], totals[:it_blocks]]
nesting_depth&.times { total_values << '' }
total_values << totals[:redefinitions]
total_values << totals[:before_creates]
total_format = '| %-58s | %8d | %8d | %8d |'
total_format += (' %8s |' * nesting_depth) if nesting_depth
total_format += ' %8d | %8d |'
output << (total_format % total_values)
output << separator
formatted_output = output.join("\n")
formatted_output += "\n\n#{format_factory_stats(analyzer, limit)}" if analyzer.factory_stats
formatted_output
end
|