Ruby - リンクチェック - outputhtml.rb html ドキュメント出力

クラウディア 
1. html ドキュメント出力

1. html ドキュメント出力

 「html」ドキュメントの出力です。
#!/usr/bin/env ruby
=begin

結果の出力を行う

=end

require('pry')
require('openssl')
require('readconf')
require('checkparent')

class OutputHTML
  def initialize()
  end

  def execute(starttime, finishtime, checked, file)
    begin
      file.puts('<!DOCTYPE HTML>')
      file.puts('<html>')
      file.puts('<head>')
      file.puts('<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>')
      file.puts('<title>'"Show's"' LinkChecker '"#{$version}"'</title>')
      file.puts('<style type="text/css">
<!--
h2 { font-family: Verdana,sans-serif; font-size: 22pt; font-weight: bold; }
body { font-family: Arial,sans-serif; font-size: 11pt; background-color: #fff7e5; }
td { font-family: Arial,sans-serif; font-size: 11pt; }
code { font-family: Courier; }
a:link {color: #191c83;}
a:visited {color: #191c83;}
a:active {color: #191c83;}
a:hover { color: #34a4ef; }
table { border-collapse:collapse; }
table, th, td { border: 1px solid black; padding: 2px; }
td.url { background-color: #dcd5cf }
td.valid { background-color: #3ba557 }
td.error { background-color: #db4930 }
td.warning { background-color: #e0954e }
-->
</style>')
      file.puts('</head>')
      file.puts('<body>')
      file.puts('<!-- Generated by '"Show's"' LinkChecker '"#{$version}"' --><h2>'"Show's"' LinkChecker '"#{$version}"'</h2><br/><blockquote>')
      file.puts('</br>開始 '+sprintf("%04d年%d月%d日 %02d:%02d:%02d", starttime.year, starttime.mon, starttime.day, starttime.hour, starttime.min, starttime.sec))
      file.puts('</br>終了 '+sprintf("%04d年%d月%d日 %02d:%02d:%02d", finishtime.year, finishtime.mon, finishtime.day, finishtime.hour, finishtime.min, finishtime.sec))

      diff = (finishtime - starttime).to_i
      hour = diff/(60*60)
      diff -= hour * (60*60)
      min = diff/60
      sec = diff - (min * 60)

      puts(sprintf("%d:%02d:%02d", hour, min, sec))
      file.puts('</br>時間 '+sprintf("%d:%02d:%02d", hour, min, sec))

      file.puts('</br>')

      $errorURL.each do | key, value |
        file.puts('</br>')
        file.print('<table>')
        file.print('<tr><td class="url">URL</td><td class="url">'"#{key}"'</td></tr>')
        file.print('<tr><td>リンク元</td><td><a target="top" href="'"#{value[:リンク元]}"'">'"#{value[:リンク元]}"'</a></td></tr>')
        file.print('<tr><td>リンク先</td><td><a target="top" href="'"#{key}"'">'"#{value[:リンク]}"'</a></td></tr>')
        file.print('<tr><td class="error">結果</td><td class="error">'"#{value[:結果]}"'</td></tr>')
        file.print('</table>')
      end

      file.puts('</br>チェックしたリンク数 '+checked.count.to_s.reverse.gsub( /(\d{3})(?=\d)/, '\1,').reverse+'  エラー発生数'+$errorURL.count.to_s.reverse.gsub( /(\d{3})(?=\d)/, '\1,').reverse)
      file.puts('</blockquote><br/><hr><small>'"Show's"' LinkChecker '"#{$version}"', Copyright &copy; Show.Kit&nbsp;Kleineidam<br/></small>')
      file.puts('</body>')
      file.puts('</html>')
    rescue => error
      exeptlog = ExceptLog.new
      binding.pry
      exeptlog.execute(self, error)
      exit 1
    end
  end
end