Module: ResultIndexGenerator

Included in:
SaikuroCMDLineRunner, SaikuroRunner
Defined in:
lib/saikuro.rb

Instance Method Summary collapse

Instance Method Details

#list_analyzed_files(files) ⇒ Object



907
908
909
910
911
912
913
914
915
916
917
918
919
# File 'lib/saikuro.rb', line 907

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


896
897
898
899
900
901
902
903
904
905
# File 'lib/saikuro.rb', line 896

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



870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
# File 'lib/saikuro.rb', line 870

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



939
940
941
942
943
944
945
# File 'lib/saikuro.rb', line 939

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



921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
# File 'lib/saikuro.rb', line 921

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



947
948
949
950
951
952
953
# File 'lib/saikuro.rb', line 947

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