Class: Toc
- Inherits:
-
Object
- Object
- Toc
- Includes:
- Enumerable, Singleton
- Defined in:
- lib/coursegen/course/data/toc.rb
Instance Method Summary collapse
- #build_citem_table ⇒ Object
- #build_mapping_table(items) ⇒ Object
- #build_sections(items) ⇒ Object
- #citem_section(citem) ⇒ Object
- #find_next_for(citem) ⇒ Object
- #find_next_forn(nitem) ⇒ Object
- #find_previous_for(citem) ⇒ Object
- #find_previous_forn(nitem) ⇒ Object
- #lookup_citem(the_sect, item_short_name) ⇒ Object
- #n2c(nitem) ⇒ Object
- #prepare(items, config) ⇒ Object
- #record_inclusion(host_item, included_item) ⇒ Object
- #reset ⇒ Object
- #section(selector) ⇒ Object
- #section_def(selector) ⇒ Object
Instance Method Details
#build_citem_table ⇒ Object
41 42 43 |
# 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) ⇒ Object
32 33 34 35 36 37 38 39 |
# 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) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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.[:type] == :lecture schedule = Scheduler.new schedule.setup_from_schedule_def(sect.[:schedule]) @sections[selector] = Lectures.new(selector, items, schedule, sect.[:collapsed]) elsif sect.[:type] == :section @sections[selector] = Section.new(selector, items, sect.[:collapsed]) else raise ArgumentError.new("Invalid section option") end end end |
#citem_section(citem) ⇒ Object
94 95 96 |
# File 'lib/coursegen/course/data/toc.rb', line 94 def citem_section citem @sections[citem.section] end |
#find_next_for(citem) ⇒ Object
86 87 88 |
# 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) ⇒ Object
74 75 76 77 78 |
# 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) ⇒ Object
90 91 92 |
# 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) ⇒ Object
80 81 82 83 84 |
# 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) ⇒ Object
49 50 51 52 53 54 55 |
# 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) ⇒ Object
45 46 47 |
# File 'lib/coursegen/course/data/toc.rb', line 45 def n2c nitem @map_n2c[nitem.identifier] end |
#prepare(items, config) ⇒ Object
7 8 9 10 11 12 13 14 |
# 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) ⇒ Object
98 99 100 |
# File 'lib/coursegen/course/data/toc.rb', line 98 def record_inclusion host_item, included_item @info[included_item.identifier] = host_item end |
#reset ⇒ Object
57 58 59 |
# File 'lib/coursegen/course/data/toc.rb', line 57 def reset @sections = nil end |
#section(selector) ⇒ Object
61 62 63 64 65 |
# 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) ⇒ Object
67 68 69 70 71 |
# 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 |