Class: MyBanner::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/my_banner/section.rb

Defined Under Namespace

Classes: Meeting

Constant Summary collapse

WEEKDAYS_MAP =

S and N assumed but not yet verified

{ M: 1, T: 2, W: 3, R: 4, F: 5, S: 6, N: 0 }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metadata = {}) ⇒ Section

Returns a new instance of Section.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/my_banner/section.rb', line 6

def initialize(={})
  @metadata = 

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

  schedule_info = .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

Instance Attribute Details

#courseObject

Returns the value of attribute course.



4
5
6
# File 'lib/my_banner/section.rb', line 4

def course
  @course
end

#end_timeObject

Returns the value of attribute end_time.



4
5
6
# File 'lib/my_banner/section.rb', line 4

def end_time
  @end_time
end

#instructorObject

Returns the value of attribute instructor.



4
5
6
# File 'lib/my_banner/section.rb', line 4

def instructor
  @instructor
end

#locationObject

Returns the value of attribute location.



4
5
6
# File 'lib/my_banner/section.rb', line 4

def location
  @location
end

#metadataObject

Returns the value of attribute metadata.



4
5
6
# File 'lib/my_banner/section.rb', line 4

def 
  @metadata
end

#sectionObject

Returns the value of attribute section.



4
5
6
# File 'lib/my_banner/section.rb', line 4

def section
  @section
end

#start_timeObject

Returns the value of attribute start_time.



4
5
6
# File 'lib/my_banner/section.rb', line 4

def start_time
  @start_time
end

#term_endObject

Returns the value of attribute term_end.



4
5
6
# File 'lib/my_banner/section.rb', line 4

def term_end
  @term_end
end

#term_startObject

Returns the value of attribute term_start.



4
5
6
# File 'lib/my_banner/section.rb', line 4

def term_start
  @term_start
end

#time_zoneObject

Returns the value of attribute time_zone.



4
5
6
# File 'lib/my_banner/section.rb', line 4

def time_zone
  @time_zone
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/my_banner/section.rb', line 4

def title
  @title
end

#weekdaysObject

Returns the value of attribute weekdays.



4
5
6
# File 'lib/my_banner/section.rb', line 4

def weekdays
  @weekdays
end

Instance Method Details

#abbreviationObject Also known as: abbrev



28
29
30
# File 'lib/my_banner/section.rb', line 28

def abbreviation
  "#{course}-#{section}" if course && section
end

#meeting_datesObject



43
44
45
# File 'lib/my_banner/section.rb', line 43

def meeting_dates
  term_date_range.select { |date| weekday_numbers.include?(date.wday) }
end

#meetingsObject

TODO:

cross-reference the “Holidays in the United States” calendar events to make a best guess at which classes to exclude

Note:

does not exclude meetings cancelled due to holidays



35
36
37
38
39
40
41
# 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_rangeObject



47
48
49
# File 'lib/my_banner/section.rb', line 47

def term_date_range
  term_start..term_end
end

#weekday_numbersObject



51
52
53
# File 'lib/my_banner/section.rb', line 51

def weekday_numbers
  weekdays.map { |char| WEEKDAYS_MAP[char.to_sym] }
end