Newer
Older
2022-KEGO / mycgi / test / test.rb
@”Sato ”Sato on 12 Jan 2023 1 KB fix
#!/usr/bin/env ruby
# coding: utf-8

require 'cgi'
c = CGI.new(:accept_charset => "UTF-8")
print "Content-type: text/html; charset=UTF-8\n\n"

name = c["namae"]
bt   = c["blood"]

print "<!DOCTYPE html>
<html>
<head><title>Blood type</title></head>
<body>\n"

print "<h1>#{name}さんの判定結果</h1>\n"

kekka = {			# A, B, AB, O に対応する値をHashで設定する
  "ペットボトル"	=> "ペットボトル専用袋(緑)",
  "空き缶"	=> "資源物袋(青)",
  "紙おむつ"	=> "もやすごみ袋(黒)",
  "生ごみ"	=> "もやすごみ袋(黒)",
  "一輪車"	=> "粗大ごみ",
  "入れ歯"	=> "埋め立てゴミ",
  "腕時計"	=> "埋め立てゴミ",
  "絵の具"	=> "もやすごみ袋(黒)",
  "鉛筆削り器"	=> "埋め立てゴミ",
  "延長コード"	=> "もやすごみ袋(黒) 1m以内に切る",
 "斧"	=> "埋立ごみ",
  "温度計 水銀式"	=> "水銀ゴミ",
}
kekka.default = "人間なの??"	# Hashのデフォルト値(キーがない場合の値)

bt.upcase!	# 念のため大文字に変えておく
printf("<p>%s型のあなたは%s</p>\n", bt, kekka[bt])
print "</body>\n"
print "</html>\n"

print("
  <!DOCTYPE html>
  <html>
  <head><title>検索結果</title>
  <style type=\"text/css\">
  # <!--
  # body {background-color: black}
  # h1 {background-color: gold ; color: black ; text-align: center}
  #  tr.head {background: crimson; color: white ; text-align: center}
  #  tr {color : white ; text-align: center}
  #  th {color : white ; width: 10em; text-align: center}
  #  -->
  # </style>
  </head>
  <body>
  ")
  result.each{|row|
  printf("<br>品名 : 「%s」<br>ごみ区分 : 「%s」 <br><br> 備考 : %s<br>-------------------------------------------------------------------------------",row["name"], row["type"], row["remark"])}    
  puts("
  </body>
  </html>")