# today.rb v1.2 2002.12.2 by ippo # today.rb v1.3 2003.5.19 by ippo #CSS化 # today.rb v1.4a 2003.9.21 by ippo #微修正 # (modefied- enikki.rb,v 1.2 2001/09/03 22:54:46 not Exp) =begin 「今日はなんの日?」毎日冒頭記 LOG_DIRECTORYフォルダにある「なんの日?ファイル」を読み込み、毎日の冒頭に。 データ参照元へのリンクを付す。 ファイル名は「todaysf.txt」 フォーマットは各行「MMDD(tab)date(tab)string」 「#」で始まる行はコメントとして処理 @@today_file, @@today_url, today_reference_url の微修正で、 様々な「なんの日?」に対応できるはず。 =end require 'kconv' class Filter @@today_file = 'todaysf.txt' @@today_url = 'http://homepage2.nifty.com/URU/' # @@today_url = 'http://www.mars.dti.ne.jp/~nakahasi/shimada/nenpyou.html' def today(str, type) if @todaylist.nil? @todaylist = [] open(@diary.logDirectory + @@today_file).each{ |line| next if line =~ /^#/ line = Kconv.tosjis(line).chomp.split("\t") date = line.shift time = '0101' if date =~ /(\d\d)(\d\d)/ #月、日のdateデータ time = $1 + $2 end @todaylist << [time, line] } end case type when :ONEDAY list = @todaylist.find_all{ |time, data| time == @diary.date[4..7]} if list.size > 0 info = '
' << "\n" list.each{ |time, data| info << data.join(" ").strip << '
' << "\n" } url = today_reference_url unless url.nil? ref = '' info.chomp!("
\n") info << "\n" << ref << "\n" end info << '
' << "\n" str.replace("<<\n" + info + "\n\n" + str) end end end def today_reference_url #URUさんの「今日はなんの日SF版」の場合 mo = Time::local(@diary.date[0..3], @diary.date[4..5], @diary.date[6..7]).strftime("%b").downcase md = @diary.date[4..7] unless @@today_url.nil? return @@today_url + mo + '.htm#' + md # return @@today_url #某年表へのリンクにするとか(月日までリンクしない) # return nil #あるいはいっそ「→」なしにするとか else return nil end end end