#!/usr/bin/env ruby require 'cgi' cgi = CGI.new # ユーザー入力の取得 temperature = cgi['temperature'].to_i rescue nil # 気温に基づいた提案を定義 def suggest_clothing_and_breakfast(temp) case temp when -Float::INFINITY..5 { clothing: '厚手のコート、手袋、マフラー', breakfast: 'ホットココアとオートミール' } when 6..15 { clothing: 'セーターと軽いジャケット', breakfast: '温かいスープとパン' } when 16..25 { clothing: 'Tシャツとジーンズ', breakfast: 'サラダとトースト' } else { clothing: '半袖とショートパンツ', breakfast: 'フルーツと冷たいスムージー' } end end # 提案を取得 suggestion = temperature ? suggest_clothing_and_breakfast(temperature) : nil # HTTPヘッダーを出力 print cgi.header("text/html; charset=UTF-8") # HTML出力 print <
服装の提案: #{suggestion[:clothing]}
朝ご飯の提案: #{suggestion[:breakfast]}
HTML end print < HTML