# $Id: qa.rb,v 1.2 2005/01/16 02:48:35 toshio Exp $ # Copyright (C) 2004 TOSHIO FUKEHARA #============= # QAプラグイン #============= # グローバル変数 $linkDicValue = ["", "", "", "", ""] $linkDicTitle = ["", "", "", "", ""] $linkDicValue[0] = "http://dictionary.goo.ne.jp/cgi-bin/dict_search.cgi?MT=[word]&sw=0" $linkDicTitle[0] = "[goo]" $linkDicValue[1] = "http://home.alc.co.jp/db/owa/etm_sch?instr=[word]&stg=1" $linkDicTitle[1] = "[ALC語源]" $linkDicValue[2] = "http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va=[word]" $linkDicTitle[2] = "[Collegiate]" $linkDicValue[3] = "http://www1.oup.co.uk/elt/oald/cgi-bin/oald.pl?search_word=[word]" $linkDicTitle[3] = "[Oxford]" $linkDicValue[4] = "http://dictionary.reference.com/search?q=[word]" $linkDicTitle[4] = "[Dic.com]" $linkWord = "" # サニタイジング def myescape(array) array.collect!{|x| x.to_s.escapeHTML} end # 解答・チェックの表示 # <引数> 選択値、選択肢(解答1)、選択肢(解答2)、、、 def qa_answer(*answer) items = "\n
" items << qa_select(*answer) items << qa_check items << "
\n" items end # 解答・チェック表示+リンク(英語辞書サイト)を表示 # <引数> 選択値、選択肢(解答1)、選択肢(解答2)、、、 def qa_answer_link(*answer) items = "\n
" items << qa_select(*answer) items << qa_check items << qa_select_link($linkWord) items << "
\n" items end # 解答の表示 # <引数> 選択値、選択肢(解答1)、選択肢(解答2)、、、 def qa_select(*answer) answer = myescape(answer) items = "\n  \n" items end # リンク(英語辞書サイト)を表示します # <引数> 参照するキーワード(英単語) def qa_select_link(*word) word = myescape(word) items = "\n  \n" items end # リンク内容の変更 # <引数> 何番目のリンクか(0〜)、リンク内容、タイトル # リンク内容のキーワード部分は"[word]"で指定すること def qa_set_link(index, value, title) if index > $linkDicValue.size then $linkDicValue.push(value) $linkDicTitle.push(title) else $linkDicValue[index] = value $linkDicTitle[index] = title end # このままでは引数の文字列が何故か出力されてしまう為 items = "" items end # チェックの表示 # <引数> なし def qa_check <   EOS end # 問題表題の表示 # ※引数なしでも可 # <引数1> 表題 # 例 Q1 # 例 !!!Q1 # <引数2> 表示するかどうか 1 または 0 (指定なし時は表示、表題の引数の後に記述すること) def qa_title(*title) title = myescape(title) @qa_count += 1 head_start = "

" head_end = "

" if title == [] then body = "問#{@qa_count}" else $linkWord = title[0] # リンク表示用 body = title[0] case body when /^(\!{1,5})(.+)$/ scan_ret = body.scan(/^(\!{1,5})/) head_start = "" head_end = "" # 注意 # splitメソッドは !!!問3 が split_ret[0]= split_ret[1]=!!! split_ret[2]=問3 のような結果になる split_ret = body.split(/^(\!{1,5})/) body = split_ret[2] end end if title.size > 1 then flg_visible = title[1].to_i else flg_visible = 1 end items = "" items << "\n" if flg_visible == 1 then items << "#{head_start} #{body}#{head_end}\n" else items << " \n" end items end # 問題一覧の表示、保存ボタン・クリアボタンの表示 # <引数> 行数、列数、(問題数) ※引数なしでも可 def qa_base(*base) base = myescape(base) @qa_english = false @qa_count = 0 items = "" items << qa_get_base(*base) items end # 問題一覧の表示、保存ボタン・クリアボタンの表示 # <引数> 行数、列数、(問題数) ※引数なしでも可 # 英語表記 def qa_base_e(*base) base = myescape(base) @qa_english = true @qa_count = 0 items = "" items << qa_get_base(*base) items end # 問題一覧の表示、保存ボタン・クリアボタンの表示内容の取得 def qa_get_base(*base) if base == [] then cells = 50 cols = 10 else cells = base[0].to_i * 10 if base.size > 1 then cols = base[1].to_i cells = base[0].to_i * base[1].to_i else cols = 10 end if base.size > 2 then cells = base[2].to_i end end items = < EOS count = 0 1.upto(cells) do |i| if count == cols then items << "\n" items << "\n" count = 0 end if @qa_english then items << "Q#{i}×\n" else items << "問#{i}×\n" end count += 1 end items << < EOS items << "\n" items << < EOS if @qa_english then items << "
\n" items << "\n" items << " \n" items << "\n" items << "
\n" else items << "
\n" items << "\n" items << " \n" items << "\n" items << "
\n" end # 出力 items end