class Schedule::Month

Month in yearly Schedule::Schedule

Attributes

date[R]
name[R]

January, February …

weeks[R]

List of Weeks

Public Class Methods

new(year, month) click to toggle source
# File app/models/schedule/month.rb, line 13
def initialize(year, month)
  @year = year
  @month = month
  @name = Date::MONTHNAMES[month]
  @name_abbr = Date::ABBR_MONTHNAMES[month]
  @weeks = []
  @date = Date.new(year, month, 1)
  day = monday_of_week(@date)
  end_of_month = Date.new(year, month).to_time.at_end_of_month
  until day.to_time > end_of_month
    @weeks << Week.new(self, day)
    day = day + 7
  end
end

Public Instance Methods

add(event) click to toggle source
# File app/models/schedule/month.rb, line 40
def add(event)
  day_of_month = event.date.day
  @weeks.each do |week|
    week.days.each do |day|
      if !day.other_month? && day_of_month == day.day_of_month
        day.events << event
        return
      end
    end
  end
end
monday_of_week(day) click to toggle source

Monday of this week’s day as a number

# File app/models/schedule/month.rb, line 33
def monday_of_week(day)
  until day.wday == 0
    day = day - 1
  end
  day
end
name_abbr() click to toggle source
# File app/models/schedule/month.rb, line 28
def name_abbr
  @name_abbr
end
to_s() click to toggle source
# File app/models/schedule/month.rb, line 52
def to_s
  "#<Schedule::Month #{name} #{date.strftime('%x') if date}>"
end