module MetricFu::FlogReporter class Generator class << self def generate_report(base_dir) flog_hashes = [] Dir.glob("#{base_dir}/**/*.txt").each do |filename| content = "" File.open(filename, "r").each_line do |file| content << file end begin page = Base.parse(content) rescue InvalidFlog puts "Invalid flog for #{filename}" next end next unless page if MetricFu::MD5Tracker.file_already_counted?(filename) flog_hashes << { :page => page, :path => filename.sub('.txt', '.html').sub("#{base_dir}/", "") } else flog_hashes << generate_page(filename, page, base_dir) end end generate_index(flog_hashes, base_dir) end def generate_page(filename, page, base_dir) html_file = File.new(filename.gsub(/\.txt/, '.html'), "w") html_file.puts page.to_html html_file.close return { :path => html_file.path.sub("#{base_dir}/", ''), :page => page } end def generate_index(flog_hashes, base_dir) html = "
Flogged files
\n" html << "Generated on #{Time.now.localtime} with flog
\n" html << "File | Total score | Methods | Average score | Highest score |
---|---|---|---|---|
#{flog_hash[:path].sub('.html', '.rb')} | #{sprintf(SCORE_FORMAT, flog_hash[:page].score)} | #{flog_hash[:page].scanned_methods.length} | #{sprintf(SCORE_FORMAT, flog_hash[:page].average_score)} | #{sprintf(SCORE_FORMAT, flog_hash[:page].highest_score)} |