class MyBanner::Section

Constants

WEEKDAYS_MAP

Attributes

course[RW]
end_time[RW]
instructor[RW]
location[RW]
metadata[RW]
section[RW]
start_time[RW]
term_end[RW]
term_start[RW]
time_zone[RW]
title[RW]
weekdays[RW]

Public Class Methods

new(metadata={}) click to toggle source
# File lib/my_banner/section.rb, line 6
def initialize(metadata={})
  @metadata = metadata

  @course = metadata.try(:[], :course)
  @section = metadata.try(:[], :section)
  @title = metadata.try(:[], :title)

  schedule_info = metadata.try(:[], :scheduled_meeting_times)
  @instructor = schedule_info.try(:[], :instructors).try(:first)
  @weekdays = schedule_info.try(:[], :days).try(:each_char).try(:to_a)
  @location = schedule_info.try(:[], :where)
  @time_zone = "America/New_York" #todo: lookup or customize

  term_info = schedule_info.try(:[], :date_range) #todo: validate string splits into two-member array
  @term_start = Date.parse( term_info.try(:split, " - ").try(:first) ) rescue nil
  @term_end = Date.parse( term_info.try(:split, " - ").try(:last) ) rescue nil

  time_info = schedule_info.try(:[], :time) #todo: validate string splits into two-member array
  @start_time = time_info.try(:split, " - ").try(:first)
  @end_time = time_info.try(:split, " - ").try(:last)
end

Public Instance Methods

abbrev()
Alias for: abbreviation
abbreviation() click to toggle source
# File lib/my_banner/section.rb, line 28
def abbreviation
  "#{course}-#{section}" if course && section
end
Also aliased as: abbrev
meeting_dates() click to toggle source
# File lib/my_banner/section.rb, line 43
def meeting_dates
  term_date_range.select { |date| weekday_numbers.include?(date.wday) }
end
meetings() click to toggle source

@note does not exclude meetings cancelled due to holidays @todo cross-reference the “Holidays in the United States” calendar events to make a best guess at which classes to exclude

# File lib/my_banner/section.rb, line 35
def meetings
  meeting_dates.map do |date|
    start_at = DateTime.parse("#{date} #{start_time}")
    end_at = DateTime.parse("#{date} #{end_time}")
    Meeting.new(start_at: start_at, end_at: end_at)
  end
end
term_date_range() click to toggle source
# File lib/my_banner/section.rb, line 47
def term_date_range
  term_start..term_end
end
weekday_numbers() click to toggle source
# File lib/my_banner/section.rb, line 51
def weekday_numbers
  weekdays.map { |char| WEEKDAYS_MAP[char.to_sym] }
end