Class: Xmvc::Stats::Statistics
- Inherits:
-
Object
- Object
- Xmvc::Stats::Statistics
- Defined in:
- lib/xmvc/stats.rb
Instance Method Summary collapse
-
#column_headings ⇒ Object
Mappings between method and human names for column headings.
-
#column_order ⇒ Object
The statistics columns to show, in order.
-
#column_width ⇒ Object
Calculates the width of all columns but the first.
- #controller_files ⇒ Object
- #controller_specs ⇒ Object
- #lib_files ⇒ Object
-
#line_headings ⇒ Object
Mappings between method and human names for line headings.
-
#line_order ⇒ Object
The lines to show, in order.
- #model_files ⇒ Object
- #model_specs ⇒ Object
-
#output ⇒ Object
Prints statistics to the console.
- #plugin_files ⇒ Object
-
#print_headings ⇒ Object
Prints a headings line based on column_order.
-
#print_line(line_elements) ⇒ Object
Prints an array of string as a line.
-
#print_separator ⇒ Object
Prints a separator line.
-
#print_summary ⇒ Object
Prints a summary line with total LOC.
- #print_totals ⇒ Object
-
#project_code_arrays ⇒ Object
The arrays to use when calculating totals for project LOC etc.
-
#project_spec_arrays ⇒ Object
The arrays to use when calculating totals for project spec LOC etc.
-
#statistics ⇒ Object
Gathers and aggregates all project statistics.
-
#title_width ⇒ Object
Calculates the width of the first column.
- #view_files ⇒ Object
- #view_specs ⇒ Object
Instance Method Details
#column_headings ⇒ Object
Mappings between method and human names for column headings
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/xmvc/stats.rb', line 159 def column_headings { :line_count => "Lines", :loc_count => "LOC", :file_count => "Classes", :method_count => "Methods", :average_methods => "M/C", :method_length => "LOC/M", :class_length => "LOC/C" } end |
#column_order ⇒ Object
The statistics columns to show, in order
125 126 127 |
# File 'lib/xmvc/stats.rb', line 125 def column_order [:line_count, :loc_count, :file_count, :class_length] end |
#column_width ⇒ Object
Calculates the width of all columns but the first. Elements will be padded to this width
120 121 122 |
# File 'lib/xmvc/stats.rb', line 120 def column_width column_headings.values.collect {|l| l.to_s.length}.max + 2 end |
#controller_files ⇒ Object
171 172 173 |
# File 'lib/xmvc/stats.rb', line 171 def controller_files files_in('app/controllers') + ['app/App.js'] end |
#controller_specs ⇒ Object
191 192 193 |
# File 'lib/xmvc/stats.rb', line 191 def controller_specs files_in('spec/controllers') end |
#lib_files ⇒ Object
183 184 185 |
# File 'lib/xmvc/stats.rb', line 183 def lib_files files_in('lib') end |
#line_headings ⇒ Object
Mappings between method and human names for line headings
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/xmvc/stats.rb', line 145 def line_headings { :controller_files => "Controllers", :model_files => "Models", :view_files => "Views", :lib_files => "Libraries", :plugin_files => "Plugins", :controller_specs => "Controller Specs", :model_specs => "Model Specs", :view_specs => "View Specs" } end |
#line_order ⇒ Object
The lines to show, in order
130 131 132 |
# File 'lib/xmvc/stats.rb', line 130 def line_order [:controller_files, :model_files, :view_files, :lib_files, :controller_specs, :model_specs, :view_specs] end |
#model_files ⇒ Object
175 176 177 |
# File 'lib/xmvc/stats.rb', line 175 def model_files files_in('app/models') end |
#model_specs ⇒ Object
195 196 197 |
# File 'lib/xmvc/stats.rb', line 195 def model_specs files_in('spec/models') end |
#output ⇒ Object
Prints statistics to the console
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/xmvc/stats.rb', line 46 def output print_headings line_order.each do |line_name| stats = statistics[line_name] arr = [line_headings[line_name]] + column_order.collect {|col| stats[col]} print_line(arr) end print_separator print_summary end |
#plugin_files ⇒ Object
187 188 189 |
# File 'lib/xmvc/stats.rb', line 187 def plugin_files files_in('vendor/plugins') end |
#print_headings ⇒ Object
Prints a headings line based on column_order
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/xmvc/stats.rb', line 61 def print_headings puts print_separator columns = ["Name"]; column_order.each {|heading| columns.push(column_headings[heading])} print_line(columns) print_separator end |
#print_line(line_elements) ⇒ Object
Prints an array of string as a line
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/xmvc/stats.rb', line 100 def print_line(line_elements) str = "| " line_elements.each_with_index do |element, index| if index == 0 str += element.to_s.ljust(title_width) + " | " else str += element.to_s.rjust(column_width) + " | " end end puts str end |
#print_separator ⇒ Object
Prints a separator line
89 90 91 92 93 94 95 96 97 |
# File 'lib/xmvc/stats.rb', line 89 def print_separator str = "+" + "-" * (title_width + 2) column_order.length.times do str += "+" + "-" * (column_width + 2) end puts str + '+' end |
#print_summary ⇒ Object
Prints a summary line with total LOC
80 81 82 83 84 85 86 |
# File 'lib/xmvc/stats.rb', line 80 def print_summary stats = [statistics[:total_code_loc], statistics[:total_spec_loc]] stats.push(stats[1].to_f / stats[0].to_f) puts " Code LOC: %s Test LOC: %s Code to Test Ratio: 1:%1.1f" % stats puts end |
#print_totals ⇒ Object
72 73 74 75 76 77 |
# File 'lib/xmvc/stats.rb', line 72 def print_totals # columns = ["Totals"] # column_order.collect {|c| statistics} # print_line(columns) end |
#project_code_arrays ⇒ Object
The arrays to use when calculating totals for project LOC etc
135 136 137 |
# File 'lib/xmvc/stats.rb', line 135 def project_code_arrays [:controller_files, :model_files, :view_files, :lib_files] end |
#project_spec_arrays ⇒ Object
The arrays to use when calculating totals for project spec LOC etc
140 141 142 |
# File 'lib/xmvc/stats.rb', line 140 def project_spec_arrays [:controller_specs, :model_specs, :view_specs] end |
#statistics ⇒ Object
Gathers and aggregates all project statistics
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/xmvc/stats.rb', line 28 def statistics @statistics ||= begin stats = {} # Calculate requested stats line_order.each do |line| stats[line] = array_statistics(self.send(line)) end # Calculate totals stats[:total_code_loc] = project_code_arrays.inject(0) {|sum, e| sum + stats[e][:loc_count]} stats[:total_spec_loc] = project_spec_arrays.inject(0) {|sum, e| sum + stats[e][:loc_count]} stats end end |
#title_width ⇒ Object
Calculates the width of the first column. Elements will be padded to this width
115 116 117 |
# File 'lib/xmvc/stats.rb', line 115 def title_width line_headings.values.collect {|l| l.to_s.length}.max + 8 end |
#view_files ⇒ Object
179 180 181 |
# File 'lib/xmvc/stats.rb', line 179 def view_files files_in('app/views') end |
#view_specs ⇒ Object
199 200 201 |
# File 'lib/xmvc/stats.rb', line 199 def view_specs files_in('spec/views') end |