class Section
Attributes
section[R]
Public Class Methods
new(sect, citems, collapsed)
click to toggle source
# File lib/coursegen/course/data/section.rb, line 9 def initialize(sect, citems, collapsed) @section = sect @collapsed = collapsed @citems = section_filter(citems) sort_pages end
Public Instance Methods
[](ind)
click to toggle source
# File lib/coursegen/course/data/section.rb, line 27 def [](ind) @citems[ind] end
collapsed?()
click to toggle source
# File lib/coursegen/course/data/section.rb, line 54 def collapsed? @collapsed end
find_by_short_name(sname)
click to toggle source
# File lib/coursegen/course/data/section.rb, line 20 def find_by_short_name(sname) matches = @citems.select { |c| sname == c.short_name } raise RuntimeError,"'#{sname}': invalid reference in section \"#{@section}\"" if matches.length == 0 raise RuntimeError, "'#{sname}': duplicate referenced in section \"#{@section}\"" if matches.length != 1 matches[0] end
find_index(citem)
click to toggle source
# File lib/coursegen/course/data/section.rb, line 16 def find_index(citem) @citems.find_index(citem) end
has_lecture_numbers?()
click to toggle source
# File lib/coursegen/course/data/section.rb, line 50 def has_lecture_numbers? false end
has_subsections?()
click to toggle source
# File lib/coursegen/course/data/section.rb, line 46 def has_subsections? false end
next_for(citem)
click to toggle source
# File lib/coursegen/course/data/section.rb, line 31 def next_for(citem) index = @citems.find_index(citem) raise ArgumentError, "invalid citem in next_for" if index.nil? new_index = [index, @citems.length - 2].min @citems[new_index + 1] end
previous_for(citem)
click to toggle source
# File lib/coursegen/course/data/section.rb, line 38 def previous_for(citem) index = @citems.find_index(citem) byebug if index.nil? raise ArgumentError, "invalid citem in previous_for" if index.nil? new_index = [index, 1].max @citems[new_index - 1] end
Protected Instance Methods
lookup_citem_by_identifier(identifier)
click to toggle source
# File lib/coursegen/course/data/section.rb, line 60 def lookup_citem_by_identifier identifier res = @citems.select { |i| i.identifier.to_s == identifier } fail "TOC#lookup_citem_by_identifier failed to find: '#{identifier}'" if res.length != 1 byebug if res.length != 1 res[0] end
section_filter(citems)
click to toggle source
Remove citems that don't belong in this section, or are hidden
# File lib/coursegen/course/data/section.rb, line 68 def section_filter citems filtered_citems = citems.map do |citem| citem.section == @section && !citem.hidden? ? citem : nil end filtered_citems.compact end
sort_pages()
click to toggle source
# File lib/coursegen/course/data/section.rb, line 75 def sort_pages @citems.sort! { |a,b| a.order <=> b.order } rescue fail "sort_pages in section.rb" end