class WeeklySeries

Constants

DAYS_OF_WEEK

TODO Is this duplicated from Ruby core and standard lib?

Public Instance Methods

day_of_week() click to toggle source

0-based. Doesn’t handle multiple days of the week. Method names here are confusing.

# File app/models/weekly_series.rb, line 7
def day_of_week
  if children.empty?
    date.wday
  else
    children.sort_by(&:date).first.date.wday
  end
end
days_of_week(date_range, reload = false) click to toggle source

Array of Integers. Sunday is 0. Ordered. Duplicates removed. Caches result, even if date_range changes, and doesn't notice database changes.

# File app/models/weekly_series.rb, line 35
def days_of_week(date_range, reload = false)
  if reload || @days_of_week.nil?
    @days_of_week = WeeklySeries.connection.select_values(%Q{
        select distinct (DAYOFWEEK(date) - 1) as day_of_week 
        from events 
        where parent_id=#{self.id} and date between '#{date_range.begin.to_s(:db)}' and '#{date_range.end.to_s(:db)}'
        order by day_of_week}
    )
    @days_of_week.map! { |day| day.to_i }
  end
  @days_of_week
end
days_of_week_as_string(date_range, reload = false) click to toggle source

Formatted list. Examples:

  • Tuesday PIR: Tu

  • Track classes: M, W, F

# File app/models/weekly_series.rb, line 22
def days_of_week_as_string(date_range, reload = false)
  case days_of_week(date_range, reload).size
  when 0
    ''
  when 1
    Time::RFC2822_DAY_NAME[days_of_week(false).first]
  else
    days_of_week(false).collect { |day| DAYS_OF_WEEK[day] }.join('/')
  end
end
earliest_day_of_week(date_range, reload = false) click to toggle source
# File app/models/weekly_series.rb, line 15
def earliest_day_of_week(date_range, reload = false)
  days_of_week(date_range, reload).min || -1
end
to_s() click to toggle source
# File app/models/weekly_series.rb, line 48
def to_s
  "<#{self.class} #{id} #{discipline} #{name} #{date} #{children.size}>"
end