#!/usr/bin/env ruby
require 'cgi'
q = CGI.new
print %Q(Content-Type: text/html; charset=EUC-JP
OO度チェック
)
name = q['name'].to_s
code = q['code'].to_s
if (code != '')
s = 0
cnt = 0
ecnt = 0
wcnt = 0
bscnt = 0
code.each_byte do |b|
s += b
cnt += 1
if b > 0x7f
ecnt += 1
end
if b.chr =~ /[\r\n \t]/
wcnt += 1
end
if b.chr == '\\'
bscnt += 1
end
end
score = s % 100
comment = ['あなたのコードは全然OOじゃないのでコンパイルエラーです。さようなら。もう来なくていいです。',
'あんまりかっこよくないのでウォーニングです。ひどいものですよ実際。',
'それなりにOOです。人並。凡人。及第点。',
'かなりのOOレヴェルです! デザパタとかそんな感じで次のステップを目指しましょう。',
'神です。なんかUMLとかXPとかJavaで.Netです。すごいです。'][score/21]
if (ecnt * 2 > cnt)
score = '???'
comment = 'コードというより日本語なのでは無いでしょうか。それともなでしことかですか。'
end
if (cnt == wcnt)
score = '100'
comment = 'WhiteSpaceキター!'
end
if (bscnt * 10 > cnt)
score = '0'
comment = 'TeXですか。はやくπになって下さい。'
end
if (cnt < 20)
score = '???'
comment = '短すぎて判定できませんこと'
end
print %Q(#{name}さんのOO度は#{score}点です!
#{comment}
)
print '
'
end
print %Q(
)