From 46580b51477355fece514573c88cb67030f4a502 Mon Sep 17 00:00:00 2001 From: drbrain Date: Thu, 1 Apr 2010 07:45:16 +0000 Subject: Import RDoc 2.5 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/stats.rb | 216 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 174 insertions(+), 42 deletions(-) (limited to 'lib/rdoc/stats.rb') diff --git a/lib/rdoc/stats.rb b/lib/rdoc/stats.rb index e18e3c23d7..8f51cbedcc 100644 --- a/lib/rdoc/stats.rb +++ b/lib/rdoc/stats.rb @@ -1,113 +1,245 @@ require 'rdoc' ## -# Simple stats collector +# RDoc stats collector class RDoc::Stats - attr_reader :num_classes + attr_reader :nodoc_constants + attr_reader :nodoc_methods + + attr_reader :num_constants attr_reader :num_files attr_reader :num_methods - attr_reader :num_modules - def initialize(verbosity = 1) - @num_classes = 0 - @num_files = 0 - @num_methods = 0 - @num_modules = 0 + attr_reader :total_files + + def initialize(total_files, verbosity = 1) + @nodoc_constants = 0 + @nodoc_methods = 0 + + @num_constants = 0 + @num_files = 0 + @num_methods = 0 + + @total_files = total_files @start = Time.now @display = case verbosity - when 0 then Quiet.new - when 1 then Normal.new - else Verbose.new + when 0 then Quiet.new total_files + when 1 then Normal.new total_files + else Verbose.new total_files end end + def begin_adding + @display.begin_adding + end + def add_alias(as) @display.print_alias as @num_methods += 1 + @nodoc_methods += 1 if as.document_self and as.comment.empty? end def add_class(klass) @display.print_class klass - @num_classes += 1 + end + + def add_constant(constant) + @display.print_constant constant + @num_constants += 1 + @nodoc_constants += 1 if constant.document_self and constant.comment.empty? end def add_file(file) - @display.print_file file + @display.print_file @num_files, file @num_files += 1 end def add_method(method) @display.print_method method @num_methods += 1 + @nodoc_methods += 1 if method.document_self and method.comment.empty? end def add_module(mod) @display.print_module mod - @num_modules += 1 + end + + def done_adding + @display.done_adding end def print - puts "Files: #@num_files" - puts "Classes: #@num_classes" - puts "Modules: #@num_modules" - puts "Methods: #@num_methods" - puts "Elapsed: " + sprintf("%0.1fs", Time.now - @start) + classes = RDoc::TopLevel.classes + num_classes = classes.length + nodoc_classes = classes.select do |klass| + klass.document_self and klass.comment.empty? + end.length + + modules = RDoc::TopLevel.modules + num_modules = modules.length + nodoc_modules = modules.select do |mod| + mod.document_self and mod.comment.empty? + end.length + + items = num_classes + @num_constants + num_modules + @num_methods + doc_items = items - + nodoc_classes - @nodoc_constants - nodoc_modules - @nodoc_methods + + percent_doc = doc_items.to_f / items * 100 + + puts "Files: %5d" % @num_files + puts "Classes: %5d (%5d undocumented)" % [num_classes, nodoc_classes] + puts "Constants: %5d (%5d undocumented)" % + [@num_constants, @nodoc_constants] + puts "Modules: %5d (%5d undocumented)" % [num_modules, nodoc_modules] + puts "Methods: %5d (%5d undocumented)" % [@num_methods, @nodoc_methods] + puts "%6.2f%% documented" % percent_doc + puts + puts "Elapsed: %0.1fs" % (Time.now - @start) end + ## + # Stats printer that prints nothing + class Quiet + + def initialize total_files + @total_files = total_files + end + + ## + # Prints a message at the beginning of parsing + + def begin_adding(*) end + + ## + # Prints when an alias is added + def print_alias(*) end + + ## + # Prints when a class is added + def print_class(*) end + + ## + # Prints when a constant is added + + def print_constant(*) end + + ## + # Prints when a file is added + def print_file(*) end + + ## + # Prints when a method is added + def print_method(*) end + + ## + # Prints when a module is added + def print_module(*) end + + ## + # Prints when RDoc is done + + def done_adding(*) end + end - class Normal - def print_alias(as) - print 'a' + ## + # Stats printer that prints just the files being documented with a progress + # bar + + class Normal < Quiet + + def begin_adding # :nodoc: + puts "Parsing sources..." end - def print_class(klass) - print 'C' + ## + # Prints a file with a progress bar + + def print_file(files_so_far, filename) + progress_bar = sprintf("%3d%% [%2d/%2d] ", + 100 * (files_so_far + 1) / @total_files, + files_so_far + 1, + @total_files) + + if $stdout.tty? + # Print a progress bar, but make sure it fits on a single line. Filename + # will be truncated if necessary. + terminal_width = (ENV['COLUMNS'] || 80).to_i + max_filename_size = terminal_width - progress_bar.size + if filename.size > max_filename_size + # Turn "some_long_filename.rb" to "...ong_filename.rb" + filename = filename[(filename.size - max_filename_size) .. -1] + filename[0..2] = "..." + end + + # Pad the line with whitespaces so that leftover output from the + # previous line doesn't show up. + line = "#{progress_bar}#{filename}" + padding = terminal_width - line.size + line << (" " * padding) if padding > 0 + + $stdout.print("#{line}\r") + $stdout.flush + else + puts "#{progress_bar} #{filename}" + end end - def print_file(file) - print "\n#{file}: " + def done_adding # :nodoc: + puts end - def print_method(method) - print 'm' + end + + ## + # Stats printer that prints everything documented, including the documented + # status + + class Verbose < Normal + + ## + # Returns a marker for RDoc::CodeObject +co+ being undocumented + + def nodoc co + " (undocumented)" unless co.documented? end - def print_module(mod) - print 'M' + def print_alias as # :nodoc: + puts "\t\talias #{as.new_name} #{as.old_name}#{nodoc as}" end - end - class Verbose - def print_alias(as) - puts "\t\talias #{as.new_name} #{as.old_name}" + def print_class(klass) # :nodoc: + puts "\tclass #{klass.full_name}#{nodoc klass}" end - def print_class(klass) - puts "\tclass #{klass.full_name}" + def print_constant(constant) # :nodoc: + puts "\t\t#{constant.name}#{nodoc constant}" end - def print_file(file) - puts file + def print_file(files_so_far, file) # :nodoc: + super + puts end - def print_method(method) - puts "\t\t#{method.singleton ? '::' : '#'}#{method.name}" + def print_method(method) # :nodoc: + puts "\t\t#{method.singleton ? '::' : '#'}#{method.name}#{nodoc method}" end - def print_module(mod) - puts "\tmodule #{mod.full_name}" + def print_module(mod) # :nodoc: + puts "\tmodule #{mod.full_name}#{nodoc mod}" end + end end -- cgit v1.2.3