Class: Dcov::Stats
- Inherits:
-
Object
- Object
- Dcov::Stats
- Defined in:
- lib/dcov/stats.rb
Overview
RDoc’s Stats class with our own stats thrown in and our own custom print method.
Instance Attribute Summary collapse
-
#coverage ⇒ Object
Returns the value of attribute coverage.
-
#num_classes ⇒ Object
Returns the value of attribute num_classes.
-
#num_files ⇒ Object
Returns the value of attribute num_files.
-
#num_methods ⇒ Object
Returns the value of attribute num_methods.
-
#num_modules ⇒ Object
Returns the value of attribute num_modules.
Instance Method Summary collapse
-
#coverage_rating(tokens) ⇒ Object
Get the coverage rating (e.g., 34%) for the tokens of the type specified.
-
#initialize ⇒ Stats
constructor
include Ruport::Renderer::Hooks renders_with Dcov::StatsRenderer.
-
#print ⇒ Object
Print out the coverage rating.
- #renderable_data ⇒ Object
Constructor Details
#initialize ⇒ Stats
include Ruport::Renderer::Hooks renders_with Dcov::StatsRenderer
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dcov/stats.rb', line 39 def initialize @num_files = @num_classes = @num_modules = @num_methods = 0 @start = Time.now @coverage = { } [:class, :method, :module].each do |type| @coverage[type] = { :covered => [], :not_covered => [] } end @coverage[:tokens] = {} end |
Instance Attribute Details
#coverage ⇒ Object
Returns the value of attribute coverage.
34 35 36 |
# File 'lib/dcov/stats.rb', line 34 def coverage @coverage end |
#num_classes ⇒ Object
Returns the value of attribute num_classes.
34 35 36 |
# File 'lib/dcov/stats.rb', line 34 def num_classes @num_classes end |
#num_files ⇒ Object
Returns the value of attribute num_files.
34 35 36 |
# File 'lib/dcov/stats.rb', line 34 def num_files @num_files end |
#num_methods ⇒ Object
Returns the value of attribute num_methods.
34 35 36 |
# File 'lib/dcov/stats.rb', line 34 def num_methods @num_methods end |
#num_modules ⇒ Object
Returns the value of attribute num_modules.
34 35 36 |
# File 'lib/dcov/stats.rb', line 34 def num_modules @num_modules end |
Instance Method Details
#coverage_rating(tokens) ⇒ Object
Get the coverage rating (e.g., 34%) for the tokens of the type specified
97 98 99 100 101 102 |
# File 'lib/dcov/stats.rb', line 97 def (tokens) = ((@coverage[tokens][:covered].size.to_f / (@coverage[tokens][:covered].size.to_f + @coverage[tokens][:not_covered].size.to_f)) * 100) # If it's NaN (for whatever reason, be it an irrational or irrationally small number), return 0 (.nan?) ? 0 : .to_i end |
#print ⇒ Object
Print out the coverage rating
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/dcov/stats.rb', line 53 def print # TODO: add a flag for textmate, the ugliest format ever: # txmt://open?url=file:///path/to/file.rb&line=86&column=3 puts "Files: #{@num_files}" puts "Total Classes: #{@num_classes}" puts "Total Modules: #{@num_modules}" puts "Total Methods: #{@num_methods}" puts puts "Module coverage: #{(:module)}%" puts " Not covered:" @coverage[:module][:not_covered].sort_by {|o| o.name}.each do |itm| location = itm.in_files.first.file_absolute_name || "no known location" puts " #{itm.name}:" puts " #{location}" end puts puts puts "Class coverage: #{(:class)}%" puts " Not covered:" @coverage[:class][:not_covered].sort_by {|o| o.name}.each do |itm| location = itm.in_files.first.file_absolute_name puts " #{itm.name}" puts " #{location}" end puts puts puts "Method coverage: #{(:method)}%\n" puts " Not covered:" @coverage[:method][:not_covered].sort_by {|o| [o.parent.name, o.name]}.each do |itm| location = itm.token_stream.first.text.sub(/^# File /, '').sub(/, line (\d+)$/, ':\1') puts " #{itm.parent.name}##{itm.name}:" puts " #{location}" end puts end |
#renderable_data ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/dcov/stats.rb', line 104 def renderable_data data = {} data[:coverage_rating] = {} [:class, :method, :module].each do |token| data[:coverage_rating][token] = (token) end classes = @coverage[:class][:not_covered] + @coverage[:class][:covered] modules = @coverage[:module][:not_covered] + @coverage[:module][:covered] methods = @coverage[:method][:not_covered] + @coverage[:method][:covered] # Create a properly nested structure data[:structured] = {} classes.each {|cls| data[:structured][cls.full_name] = [cls, []]} modules.each {|mod| data[:structured][mod.full_name] = [mod, []]} data[:structured]['[Toplevel]'] = [TopLevel.new, []] methods.each do |method| if (data[:structured].has_key?(method.parent.full_name)) data[:structured][method.parent.full_name][1] << method else data[:structured]['[Toplevel]'][1] << method end end data[:analyzed] = @coverage data end |