class Toc
Public Instance Methods
build_citem_table()
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 41 def build_citem_table @citems = @map_n2c.map { |k, v| v} end
build_mapping_table(items)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 32 def build_mapping_table items @map_n2c = {} items.each do |nitem| citem = CItem.new(nitem) @map_n2c[nitem.identifier] = citem end end
build_sections(items)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 16 def build_sections items @sections = {} @section_config.each do |sect| selector = sect.selector.to_s if sect.options[:type] == :lecture schedule = Scheduler.new schedule.setup_from_schedule_def(sect.options[:schedule]) @sections[selector] = Lectures.new(selector, items, schedule, sect.options[:collapsed]) elsif sect.options[:type] == :section @sections[selector] = Section.new(selector, items, sect.options[:collapsed]) else raise ArgumentError.new("Invalid section option") end end end
citem_section(citem)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 94 def citem_section citem @sections[citem.section] end
find_next_for(citem)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 86 def find_next_for(citem) section(citem.section).next_for(citem) end
find_next_forn(nitem)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 74 def find_next_forn(nitem) p = find_next_for(n2c(nitem)) fail "find_next_forn" if p.nil? p end
find_previous_for(citem)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 90 def find_previous_for(citem) section(citem.section).previous_for(citem) end
find_previous_forn(nitem)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 80 def find_previous_forn(nitem) p = find_previous_for(n2c(nitem)) fail "find_previous_forn" if p.nil? p end
lookup_citem(the_sect, item_short_name)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 49 def lookup_citem the_sect, item_short_name section = section(the_sect) raise "Toc.lookup_citem: Unknown section: `#{the_sect}`" if (section.nil?) citem = section.find_by_short_name(item_short_name) raise "Toc.lookup_citem: Unknown short name: `#{item_short_name}`" if citem.nil? return citem end
n2c(nitem)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 45 def n2c nitem @map_n2c[nitem.identifier] end
prepare(items, config)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 7 def prepare items, config raise "Toc.prepare called twice!" unless @sections.nil? @section_config = config build_mapping_table items build_citem_table build_sections @citems @info = {} end
record_inclusion(host_item, included_item)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 98 def record_inclusion host_item, included_item @info[included_item.identifier] = host_item end
reset()
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 57 def reset @sections = nil end
section(selector)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 61 def section selector section = @sections[selector] fail "TOC.section: Unknown section: #{selector}" if section.nil? section end
section_def(selector)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 67 def section_def selector matching_defs = @section_config.select { |sd| sd.selector == selector} fail "Invalid selector used in section_def" if matching_defs.length != 1 matching_defs.first end
Private Instance Methods
each_by(section_selector, &block)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 118 def each_by(section_selector, &block) sub_toc = @sections[section_selector] sub_toc.sort! { |a,b| a[:order] <=> b[:order] }.each do |member| block.call(member) end end
index_in_section(item)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 114 def index_in_section item section_for(item).find_index(item) end
lookup_by_index(section, index)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 151 def lookup_by_index section, index sect = section.section if index >= @sections[sect].count index = @sections[sect].count-1 elsif index < 0 index = 0 end @sections[sect][index] end
lookup_inclusion(included_item)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 147 def lookup_inclusion included_item @info[included_item.identifier] end
sort_section_by_order(sect)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 125 def sort_section_by_order sect @sections[sect].sort! { |a,b| a[:order] <=> b[:order] } end
sort_section_by_subsection_name(sect)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 129 def sort_section_by_subsection_name(sect) items = @sections[sect] items.sort! do |item1, item2| subsection_name(sect.to_s, item1.identifier) <=> subsection_name(sect.to_s, item2.identifier) end items end
subsection_name(section_name, item_name)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 138 def subsection_name section_name, item_name item_matcher = item_name.match('\A/'+section_name+'/([^/]*)/([^/]*)/\z') if !item_matcher.nil? item_matcher[1] else "" end end
subsections(section, &block)
click to toggle source
# File lib/coursegen/course/data/toc.rb, line 104 def subsections(section, &block) items = sort_section_by_subsection_name section item_iterator = items.chunk do |item| subsection_name section.to_s, item.identifier end item_iterator.each do |subsection_item| block.call(subsection_item) end end