class Display::Calendar
Constants
- VERSION
Public Class Methods
new()
click to toggle source
# File lib/display/calendar/calendar.rb, line 5 def initialize end
Public Instance Methods
calendar(month,year)
click to toggle source
# File lib/display/calendar/calendar.rb, line 8 def calendar(month,year) firstday = get_firstday(month,year) lastday = get_lastday(month,year) wday = firstday.wday result = "" result << put_month(month,year) result << "\n" result << put_wday result << "\n" result << " " * wday firstday.day.upto(lastday.day) do |d| result << sprintf("%2d ", d.to_s) wday += 1 if wday == 7 result << "\n" wday = 0 end end result << "\n" return result end
Private Instance Methods
get_firstday(month,year)
click to toggle source
# File lib/display/calendar/calendar.rb, line 33 def get_firstday(month,year) return Date.new(year,month,1) end
get_lastday(month,year)
click to toggle source
# File lib/display/calendar/calendar.rb, line 37 def get_lastday(month,year) return Date.new(year,month,-1) end
put_month(month,year)
click to toggle source
# File lib/display/calendar/calendar.rb, line 41 def put_month(month,year) return Date.new(year,month,1).strftime("%B %Y").center(20) end
put_wday()
click to toggle source
# File lib/display/calendar/calendar.rb, line 45 def put_wday return 'Su Mo Tu We Th Fr Sa' end