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



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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/coursegen/course/data/lectures.rb', line 19

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
		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



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

def has_lecture_numbers?
	true
end

#has_subsections?Boolean



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

def has_subsections?
	true
end

#next_for(citem) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/coursegen/course/data/lectures.rb', line 58

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)


37
38
39
40
41
# File 'lib/coursegen/course/data/lectures.rb', line 37

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



67
68
69
70
71
72
73
74
# File 'lib/coursegen/course/data/lectures.rb', line 67

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

#subsectionsObject



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

def subsections
	@root.children
end

#treenode_of(citem) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/coursegen/course/data/lectures.rb', line 43

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