@@ -15,18 +15,18 @@ def initialize(root_directory)
15
15
@key_concepts = calculate_key_concepts
16
16
@projects = calculate_projects
17
17
@statistics = calculate_statistics
18
- @total = calculate_total
18
+ @code_total , @tests_total , @grand_total = calculate_totals
19
19
end
20
20
21
21
def to_s
22
22
print_header
23
23
@statistics . each { |key , stats | print_line ( key , stats ) }
24
24
print_splitter
25
25
26
- if @total
27
- print_line ( "Total " , @total )
28
- print_splitter
29
- end
26
+ print_line ( "Code" , @code_total )
27
+ print_line ( "Tests " , @tests_total )
28
+ print_line ( "Total" , @grand_total )
29
+ print_splitter
30
30
31
31
print_code_test_stats
32
32
end
@@ -111,22 +111,21 @@ def calculate_statistics
111
111
out
112
112
end
113
113
114
- def calculate_total
115
- @statistics . each_with_object ( CodeStatisticsCalculator . new ) do |pair , total |
116
- total . add ( pair . last )
114
+ def calculate_totals
115
+ # TODO: make this a single loop
116
+ code_total = @statistics . each_with_object ( CodeStatisticsCalculator . new ) do |pair , code_total |
117
+ code_total . add ( pair . last ) unless pair . last . test
117
118
end
118
- end
119
119
120
- def calculate_code
121
- code_loc = 0
122
- @statistics . each { |k , v | code_loc += v . code_lines unless v . test }
123
- code_loc
124
- end
120
+ tests_total = @statistics . each_with_object ( CodeStatisticsCalculator . new ) do |pair , tests_total |
121
+ tests_total . add ( pair . last ) if pair . last . test
122
+ end
125
123
126
- def calculate_tests
127
- test_loc = 0
128
- @statistics . each { |k , v | test_loc += v . code_lines if v . test }
129
- test_loc
124
+ grand_total = @statistics . each_with_object ( CodeStatisticsCalculator . new ) do |pair , total |
125
+ total . add ( pair . last )
126
+ end
127
+
128
+ [ code_total , tests_total , grand_total ]
130
129
end
131
130
132
131
def print_header
@@ -153,10 +152,8 @@ def print_line(name, statistics)
153
152
end
154
153
155
154
def print_code_test_stats
156
- code = calculate_code
157
- tests = calculate_tests
158
-
159
- puts " Code LOC: #{ code } Test LOC: #{ tests } Code to Test Ratio: 1:#{ sprintf ( "%.1f" , tests . to_f /code ) } "
155
+ code_to_test_ratio = @tests_total . code_lines . to_f / @code_total . code_lines
156
+ puts " Code LOC: #{ @code_total . code_lines } Test LOC: #{ @tests_total . code_lines } Code to Test Ratio: 1:#{ sprintf ( "%.1f" , code_to_test_ratio ) } "
160
157
puts ""
161
158
end
162
159
end
0 commit comments