class DCal::Cal

Constants

ABBR_DAYNAMES

Public Class Methods

new(month, year) click to toggle source
# File lib/dcal/cal.rb, line 7
def initialize(month, year)
  @month = DCal::Month.new(month, year)
  @year  = DCal::Year.new(year)
end

Public Instance Methods

month() click to toggle source
# File lib/dcal/cal.rb, line 18
def month
  @month.month
end
output() click to toggle source
# File lib/dcal/cal.rb, line 12
def output
  title    + "\n" +
    header + "\n" +
    weeks  + "\n"
end
year() click to toggle source
# File lib/dcal/cal.rb, line 22
def year
  @year
end

Private Instance Methods

cells() click to toggle source
# File lib/dcal/cal.rb, line 41
def cells
  cells = Array.new(42, "  ")

  days  = 1..@month.days_in_month
  start = @month.wday_of_first_day

  cells.each_index do |i|
    day = i - start + 1
    cells[i] = day.to_s.rjust(2) if days.cover?(day)
  end

  cells
end
header() click to toggle source
# File lib/dcal/cal.rb, line 32
def header
  ABBR_DAYNAMES.join(" ")
end
title() click to toggle source
# File lib/dcal/cal.rb, line 28
def title
  "#{@month.name} #{@year}".center(20)
end
weeks() click to toggle source
# File lib/dcal/cal.rb, line 36
def weeks
  weeks = cells.each_slice(7).to_a
  weeks.map { |week| week.join(" ") }.join("\n")
end