Class: Toc

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Singleton
Defined in:
lib/coursegen/course/lib/toc.rb,
lib/coursegen/course/data/toc.rb

Instance Method Summary collapse

Instance Method Details

#build_citem_tableObject



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.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) ⇒ Object



85
86
87
# File 'lib/coursegen/course/lib/toc.rb', line 85

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)) 
  fail "find_next_forn in toc.rb" 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))
  fail "find_prev_forn in toc.rb" 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



89
90
91
# File 'lib/coursegen/course/lib/toc.rb', line 89

def record_inclusion host_item, included_item
  @info[included_item.identifier] = host_item
end

#resetObject



54
55
56
# File 'lib/coursegen/course/lib/toc.rb', line 54

def reset
  @sections = nil
end

#section(selector) ⇒ Object

Raises:

  • (RuntimeError)


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

#section_def(selector) ⇒ Object



64
65
66
67
68
# File 'lib/coursegen/course/data/toc.rb', line 64

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