Class: LocCountAction
- Inherits:
-
BuildAction
- Object
- BuildAction
- LocCountAction
- Includes:
- LOCCountModule
- Defined in:
- lib/kwala/actions/loc_count.rb
Constant Summary collapse
- TOTAL =
"TOTAL_LOC"
- PROD_CODE =
"TOTAL_PRODUCTION_LOC"
- TEST_CODE =
"TOTAL_TEST_LOC"
Instance Method Summary collapse
- #build_action(context) ⇒ Object
- #detailed_display(context) ⇒ Object
-
#initialize ⇒ LocCountAction
constructor
A new instance of LocCountAction.
- #percent(val, total) ⇒ Object
- #sum_count(files) ⇒ Object
- #summary_display(context) ⇒ Object
Methods included from LOCCountModule
Methods inherited from BuildAction
command_line_action_name, command_line_action_names, create_action_from_command_line_name, detailed_template_file, #score, summary_template_file
Methods included from InheritanceTracker
Constructor Details
#initialize ⇒ LocCountAction
Returns a new instance of LocCountAction.
79 80 81 |
# File 'lib/kwala/actions/loc_count.rb', line 79 def initialize @file_loc = Hash.new { |h, k| h[k] = Array.new } end |
Instance Method Details
#build_action(context) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/kwala/actions/loc_count.rb', line 83 def build_action(context) (context.ruby_files + context.test_files).each do |file| @file_loc[file] = count_loc(file) end @file_loc[TOTAL] = sum_count(@file_loc.keys) @file_loc[PROD_CODE] = sum_count(context.ruby_files) @file_loc[TEST_CODE] = sum_count(context.test_files) end |
#detailed_display(context) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/kwala/actions/loc_count.rb', line 118 def detailed_display(context) template = TemplateFile.new(self.class.detailed_template_file) ares = (@file_loc.keys - [TOTAL, PROD_CODE, TEST_CODE]).sort.map do |file| code, comments, blank = *(@file_loc[file]) ttl = code + comments + blank { :file => file, :total => ttl, :code => code, :code_per => percent(code, ttl), :comments => comments, :comments_per => percent(comments, ttl), :blank => blank, :blank_per => percent(blank, ttl) } end context.amrita_data[:loc_details] = { :entry => ares } det_res = ProjectBuilderUtils.(template, context.amrita_data) det_file = "#{context.output_directory}/#{context.project_name}_loc.html" [det_file, det_res] end |
#percent(val, total) ⇒ Object
136 137 138 |
# File 'lib/kwala/actions/loc_count.rb', line 136 def percent(val, total) sprintf("%.2f%", (val.to_f / total) * 100) end |
#sum_count(files) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/kwala/actions/loc_count.rb', line 140 def sum_count(files) code = comments = blank = 0 files.each do |file| fcode, fcomments, fblank = *( @file_loc[file] ) code += fcode comments += fcomments blank += fblank end [code, comments, blank, files.size] end |
#summary_display(context) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/kwala/actions/loc_count.rb', line 94 def summary_display(context) template = TemplateFile.new(self.class.summary_template_file) ares = [ ["Total", @file_loc[TOTAL]], ["Production Code", @file_loc[PROD_CODE]], ["Test Code", @file_loc[TEST_CODE]] ].map do |ctype, cdata| code, comments, blank, files = *cdata ttl = code + comments + blank { :type => ctype, :total => ttl, :code => code, :code_per => percent(code, ttl), :comments => comments, :comments_per => percent(comments, ttl), :blank => blank, :blank_per => percent(blank, ttl) , :files => files } end context.amrita_data[:loc_results] = { :entry => ares } loc_base = "#{context.project_name}_loc.html" context.amrita_data[:loc_details] = (Amrita::e(:a, :href => loc_base) { "Lines of Code Details" } ) (template, context) end |