Class: MyBanner::Section
- Inherits:
-
Object
- Object
- MyBanner::Section
- 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
-
#course ⇒ Object
Returns the value of attribute course.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#instructor ⇒ Object
Returns the value of attribute instructor.
-
#location ⇒ Object
Returns the value of attribute location.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#section ⇒ Object
Returns the value of attribute section.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#term_end ⇒ Object
Returns the value of attribute term_end.
-
#term_start ⇒ Object
Returns the value of attribute term_start.
-
#time_zone ⇒ Object
Returns the value of attribute time_zone.
-
#title ⇒ Object
Returns the value of attribute title.
-
#weekdays ⇒ Object
Returns the value of attribute weekdays.
Instance Method Summary collapse
- #abbreviation ⇒ Object (also: #abbrev)
-
#initialize(metadata = {}) ⇒ Section
constructor
A new instance of Section.
- #meeting_dates ⇒ Object
- #meetings ⇒ Object
- #term_date_range ⇒ Object
- #weekday_numbers ⇒ Object
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
#course ⇒ Object
Returns the value of attribute course.
4 5 6 |
# File 'lib/my_banner/section.rb', line 4 def course @course end |
#end_time ⇒ Object
Returns the value of attribute end_time.
4 5 6 |
# File 'lib/my_banner/section.rb', line 4 def end_time @end_time end |
#instructor ⇒ Object
Returns the value of attribute instructor.
4 5 6 |
# File 'lib/my_banner/section.rb', line 4 def instructor @instructor end |
#location ⇒ Object
Returns the value of attribute location.
4 5 6 |
# File 'lib/my_banner/section.rb', line 4 def location @location end |
#metadata ⇒ Object
Returns the value of attribute metadata.
4 5 6 |
# File 'lib/my_banner/section.rb', line 4 def @metadata end |
#section ⇒ Object
Returns the value of attribute section.
4 5 6 |
# File 'lib/my_banner/section.rb', line 4 def section @section end |
#start_time ⇒ Object
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_end ⇒ Object
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_start ⇒ Object
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_zone ⇒ Object
Returns the value of attribute time_zone.
4 5 6 |
# File 'lib/my_banner/section.rb', line 4 def time_zone @time_zone end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/my_banner/section.rb', line 4 def title @title end |
#weekdays ⇒ Object
Returns the value of attribute weekdays.
4 5 6 |
# File 'lib/my_banner/section.rb', line 4 def weekdays @weekdays end |
Instance Method Details
#abbreviation ⇒ Object Also known as: abbrev
28 29 30 |
# File 'lib/my_banner/section.rb', line 28 def abbreviation "#{course}-#{section}" if course && section end |
#meeting_dates ⇒ Object
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 |
#meetings ⇒ Object
cross-reference the “Holidays in the United States” calendar events to make a best guess at which classes to exclude
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_range ⇒ Object
47 48 49 |
# File 'lib/my_banner/section.rb', line 47 def term_date_range term_start..term_end end |
#weekday_numbers ⇒ Object
51 52 53 |
# File 'lib/my_banner/section.rb', line 51 def weekday_numbers weekdays.map { |char| WEEKDAYS_MAP[char.to_sym] } end |