class Mcalendar::Calendar

Public Class Methods

new(year, month) click to toggle source
# File lib/mcalendar/calendar.rb, line 6
def initialize(year, month)
  @year = year
  @month = month
end

Public Instance Methods

days() click to toggle source
# File lib/mcalendar/calendar.rb, line 19
def days
  days = (1..end_of_month.day).map {|m| "%2d" % m}
  first_of_month.wday.times {days.unshift("  ")}
  days
end
end_of_month() click to toggle source
# File lib/mcalendar/calendar.rb, line 15
def end_of_month
  Date.new(@year, @month, -1)
end
first_of_month() click to toggle source
# File lib/mcalendar/calendar.rb, line 11
def first_of_month
  Date.new(@year, @month, 1)
end
month_title() click to toggle source
# File lib/mcalendar/calendar.rb, line 25
def month_title
  first_of_month.strftime("%B %Y")
end
to_s() click to toggle source
# File lib/mcalendar/calendar.rb, line 29
def to_s
  week_header = Mcalendar::DAY_OF_WEEK.join(" ")
  month_header = month_title.center(week_header.size).rstrip
  calendar = [[week_header]]
  days.each_slice(7) {|x| calendar << [x.join("  ")]}
  [month_header, calendar]
end