Module: ResultIndexGenerator

Defined in:
lib/metric_fu/saikuro/saikuro.rb

Instance Method Summary collapse

Instance Method Details

#list_analyzed_files(files) ⇒ Object



970
971
972
973
974
975
976
977
978
979
980
981
982
# File 'lib/metric_fu/saikuro/saikuro.rb', line 970

def list_analyzed_files(files)
  f = StringIO.new
  f.puts "<h2 class=\"class_name\">Analyzed Files</h2>"
  f.puts "<ul>"
  files.each do |fname, warnings, errors|
    readname = fname.split("_")[0...-1].join("_")
    f.puts "<li>"
    f.puts "<p class=\"file_name\"><a href=\"./#{fname}\">#{readname}</a>"
    f.puts "</li>"
  end
  f.puts "</ul>"
  f.string
end


959
960
961
962
963
964
965
966
967
968
# File 'lib/metric_fu/saikuro/saikuro.rb', line 959

def print_summary_table_rows(ewvals, klass_type)
  f = StringIO.new
  ewvals.sort { |a,b| b <=> a}.each do |v, vals|
    vals.sort.each do |fname, c, m|
      f.puts "<tr><td><a href=\"./#{fname}\">#{c}</a></td><td>#{m}</td>"
      f.puts "<td class=\"#{klass_type}\">#{v}</td></tr>"
    end
  end
  f.string
end

#summarize_errors_and_warnings(enw, header) ⇒ Object



933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
# File 'lib/metric_fu/saikuro/saikuro.rb', line 933

def summarize_errors_and_warnings(enw, header)
  return "" if enw.empty?
  f = StringIO.new
  erval = Hash.new { |h,k| h[k] = Array.new }
  wval = Hash.new { |h,k| h[k] = Array.new }

  enw.each do |fname, warnings, errors|
    errors.each do |c,m,v|
      erval[v] << [fname, c, m]
    end
    warnings.each do |c,m,v|
      wval[v] << [fname, c, m]
    end
  end

  f.puts "<h2 class=\"class_name\">Errors and Warnings</h2>"
  f.puts "<table width=\"100%\" border=\"1\">"
  f.puts header

  f.puts print_summary_table_rows(erval, "error")
  f.puts print_summary_table_rows(wval, "warning")
  f.puts "</table>"

  f.string
end

#write_cyclo_index(files, output_dir) ⇒ Object



1002
1003
1004
1005
1006
1007
1008
# File 'lib/metric_fu/saikuro/saikuro.rb', line 1002

def write_cyclo_index(files, output_dir)
  header = "<tr><th>Class</th><th>Method</th><th>Complexity</th></tr>"
  write_index(files,
              "#{output_dir}/index_cyclo.html",
              "Index for cyclomatic complexity",
              header)
end

#write_index(files, filename, title, header) ⇒ Object



984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# File 'lib/metric_fu/saikuro/saikuro.rb', line 984

def write_index(files, filename, title, header)
  return if files.empty?

  File.open(filename,"w") do |f|
    f.puts "<html><head><title>#{title}</title></head>"
    f.puts "#{HTMLStyleSheet.style_sheet}\n<body>"
    f.puts "<h1>#{title}</h1>"

    enw = files.find_all { |fn,w,e| (!w.empty? || !e.empty?) }

    f.puts summarize_errors_and_warnings(enw, header)

    f.puts "<hr/>"
    f.puts list_analyzed_files(files)
    f.puts "</body></html>"
  end
end

#write_token_index(files, output_dir) ⇒ Object



1010
1011
1012
1013
1014
1015
1016
# File 'lib/metric_fu/saikuro/saikuro.rb', line 1010

def write_token_index(files, output_dir)
  header = "<tr><th>File</th><th>Line #</th><th>Tokens</th></tr>"
  write_index(files,
              "#{output_dir}/index_token.html",
              "Index for tokens per line",
              header)
end