カレンダーを作る

hikiで使う自作カレンダーを作るための準備

require 'date'

# 今日を取得
today = Date.today
# 今月の開始日を取得
date  = Date.new(today.year , today.month , 1)
month = date.month

puts "- " + date.strftime("%Y年 %m月") + " -"

print "\t" * date.wday

while month == date.month
  print date.day.to_s + "\t"
  # 土曜日が来たら折り返す。
  if date.wday == 6
    puts ""
  end
  date += 1
end

puts ""

- 結果 -

 - 2006年 03月 -
                        1       2       3       4
5       6       7       8       9       10      11
12      13      14      15      16      17      18
19      20      21      22      23      24      25
26      27      28      29      30      31


あとはHTMLを組み立てるだけでいいかな。