Class: Lectures

Inherits:
Section show all
Defined in:
lib/coursegen/course/data/lectures.rb

Instance Attribute Summary

Attributes inherited from Section

#section

Instance Method Summary collapse

Methods inherited from Section

#[], #collapsed?, #find_by_short_name, #find_index

Constructor Details

#initialize(sect, citems, schedule = nil, collapsed = false) ⇒ Lectures

Returns a new instance of Lectures.



4
5
6
7
8
9
# File 'lib/coursegen/course/data/lectures.rb', line 4

def initialize(sect, citems, schedule=nil, collapsed=false)
  super sect, citems, collapsed
  @schedule = schedule || ::Scheduler.new
  @citems = sort_items
  build_tree
end

Instance Method Details

#build_treeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/coursegen/course/data/lectures.rb', line 23

def build_tree
  lecture_num = 1
  @root = Tree::TreeNode.new("root", "root")
  @citems.each do |i|
    i.lecture_number = lecture_num
    i.lecture_date = @schedule.event_date_by_index(lecture_num - 1) # Lecture numbers are base 1
    i.start_time = @schedule.event_start_times[lecture_num - 1]
    i.end_time = @schedule.event_end_times[lecture_num - 1]
    if i.type == "subsection"
      @root.add(Tree::TreeNode.new(i.subsection, i))
    elsif i.type == "page"
      parent_tree_node = parent_node_of(i)
      parent_tree_node.add(Tree::TreeNode.new(i.identifier, i))
      lecture_num += 1
    else
      raise ArgumentError, "invalid lecture page type of #{i.type}for #{i.title}"
    end
  end
end

#has_lecture_numbers?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/coursegen/course/data/lectures.rb', line 15

def has_lecture_numbers?
  true
end

#has_subsections?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/coursegen/course/data/lectures.rb', line 11

def has_subsections?
  true
end

#next_for(citem) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/coursegen/course/data/lectures.rb', line 63

def next_for(citem)
  next_node = treenode_of(citem).next_sibling
  if !next_node.nil?
    next_node.content
  else
    citem
  end
end

#parent_node_of(citem) ⇒ Object

Raises:

  • (RuntimeError)


43
44
45
46
47
# File 'lib/coursegen/course/data/lectures.rb', line 43

def parent_node_of citem
  parent_node = @root[citem.subsection]
  raise  RuntimeError, "Cant find section for item: #{citem.identifier}" if parent_node.nil?
  parent_node
end

#previous_for(citem) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/coursegen/course/data/lectures.rb', line 72

def previous_for(citem)
  prev_node = treenode_of(citem).previous_sibling
  if !prev_node.nil?
    prev_node.content
  else
    citem
  end
end

#scheduleObject



19
20
21
# File 'lib/coursegen/course/data/lectures.rb', line 19

def schedule
  @schedule
end

#subsectionsObject



59
60
61
# File 'lib/coursegen/course/data/lectures.rb', line 59

def subsections
  @root.children
end

#treenode_of(citem) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/coursegen/course/data/lectures.rb', line 49

def treenode_of citem
  @root.find do |tree_node|
    if citem.type == "subsection"
      citem.subsection == tree_node.name
    else
      citem.identifier == tree_node.name
    end
  end
end