#!/usr/bin/ruby # miniplan.rb -- 2003-08-21 by Daicyan ( http://www.taruki.com/ ) # # miniplan: MiniPlanプラグイン # キャッシュディレクトリにあるplanというファイルを読み込んで、 # まだ過ぎていない予定を表示する。 # # パラメーター: max_lines :最大表示数(デフォルトは5) # sep :セパレーター記号(デフォルトは空白) # link :予定表一覧へのリンク先URL(デフォルトは非表示) WEEK_STR = [ "", "月", "火", "水", "木", "金", "" ] # 予定表クラス class Plan # 予定文字列 def str(index) @str[index] end # 予定日付 def date(index) @date[index] end # 予定数 def length @length end # 予定表ファイルをParse def initialize ( filename ) @str = Array.new() @date = Array.new() File.open("#{filename}","r").each_line do |line| plan_date_str, plan_str = line.split(/\|/) yyyy,mm,dd = plan_date_str.split(/\//) break if ( yyyy == nil or mm == nil or dd == nil or plan_str == nil ) @date.push ( Time.local(yyyy,mm,dd,23,59,59,00) ) @str.push ( plan_str ) end @length = @date.length end # keyの日付にマッチする予定を返す) def search(key_date) return @str[@date.index(key_date)] end end # tDiaryプラグイン本体 def miniplan(max_lines = 5, sep = ' ', link = nil) today = Time.now result = [] line_count = 1 plan = Plan.new ( "#{@cache_path}/plan" ) #plan = Plan.new ( "plan" ) 0.upto(plan.length-1) do |i| if ( today < plan.date(i) ) result << format("%d/%d(%s) ", plan.date(i).month, plan.date(i).day, WEEK_STR[plan.date(i).wday] ) result << plan.str(i) line_count+=1 break if ( line_count > max_lines ) end if ( line_count > 1 ) result << sep end end if ( link != nil ) result << sep result << format("全予定", link) end return ( result ) end