Class: Toc
- Inherits:
-
Object
- Object
- Toc
- Includes:
- Enumerable, Singleton
- Defined in:
- lib/coursegen/course/lib/toc.rb
Instance Method Summary collapse
- #build_citem_table ⇒ Object
- #build_mapping_table(items) ⇒ Object
- #build_sections(items) ⇒ Object
-
#citem_section(citem) ⇒ Object
def section_for nitem sec = @sections binding.pry if sec.nil? sec end.
- #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
Instance Method Details
#build_citem_table ⇒ Object
42 43 44 |
# File 'lib/coursegen/course/lib/toc.rb', line 42 def build_citem_table @citems = @map_n2c.map { |k, v| v} end |
#build_mapping_table(items) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/coursegen/course/lib/toc.rb', line 33 def build_mapping_table items @map_n2c = {} items.each do |nitem| citem = CItem.new(nitem) @map_n2c[nitem] = citem end end |
#build_sections(items) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/coursegen/course/lib/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
def section_for nitem
sec = @sections[n2c(nitem).section]
binding.pry if sec.nil?
sec
end
91 92 93 |
# File 'lib/coursegen/course/lib/toc.rb', line 91 def citem_section citem @sections[citem.section] end |
#find_next_for(citem) ⇒ Object
77 78 79 |
# File 'lib/coursegen/course/lib/toc.rb', line 77 def find_next_for(citem) section(citem.section).next_for(citem) end |
#find_next_forn(nitem) ⇒ Object
65 66 67 68 69 |
# File 'lib/coursegen/course/lib/toc.rb', line 65 def find_next_forn(nitem) p = find_next_for(n2c(nitem)) binding.pry if p.nil? p end |
#find_previous_for(citem) ⇒ Object
81 82 83 |
# File 'lib/coursegen/course/lib/toc.rb', line 81 def find_previous_for(citem) section(citem.section).previous_for(citem) end |
#find_previous_forn(nitem) ⇒ Object
71 72 73 74 75 |
# File 'lib/coursegen/course/lib/toc.rb', line 71 def find_previous_forn(nitem) p = find_previous_for(n2c(nitem)) binding.pry if p.nil? p end |
#lookup_citem(the_sect, item_short_name) ⇒ Object
50 51 52 |
# File 'lib/coursegen/course/lib/toc.rb', line 50 def lookup_citem the_sect, item_short_name section(the_sect).find_by_short_name(item_short_name) end |
#n2c(nitem) ⇒ Object
46 47 48 |
# File 'lib/coursegen/course/lib/toc.rb', line 46 def n2c nitem @map_n2c[nitem] end |
#prepare(items, config) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/coursegen/course/lib/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
95 96 97 |
# File 'lib/coursegen/course/lib/toc.rb', line 95 def record_inclusion host_item, included_item @info[included_item.identifier] = host_item end |
#reset ⇒ Object
54 55 56 |
# File 'lib/coursegen/course/lib/toc.rb', line 54 def reset @sections = nil end |
#section(selector) ⇒ Object
58 59 60 61 62 |
# File 'lib/coursegen/course/lib/toc.rb', line 58 def section selector section = @sections[selector] raise RuntimeError, "Invalid Section: #{selector}" if section.nil? section end |