class StudentProgress::Lesson
Constants
- SECTIONS
Attributes
content_type[RW]
id[RW]
repo[RW]
title[RW]
unit[R]
Public Class Methods
all()
click to toggle source
# File lib/student_progress/lesson.rb, line 9 def self.all @@all end
build_section_hash()
click to toggle source
# File lib/student_progress/lesson.rb, line 31 def self.build_section_hash ordinal = 0 self.all.each do |lesson| if !SECTIONS[lesson.unit.topic.title] SECTIONS[lesson.unit.topic.title] = {} end if !SECTIONS[lesson.unit.topic.title][lesson.unit.title] SECTIONS[lesson.unit.topic.title][lesson.unit.title] = { "Readme" => lesson.content_type == "Readme" ? 1 : 0, "Lab" => lesson.content_type == "Lab" ? 1 : 0, "Project" => lesson.content_type == "Project" ? 1 : 0, "ordinal" => ordinal } ordinal += 1 else SECTIONS[lesson.unit.topic.title][lesson.unit.title][lesson.content_type] += 1 end end end
create_from_hash(hash)
click to toggle source
# File lib/student_progress/lesson.rb, line 13 def self.create_from_hash(hash) new(hash).save end
find_by_id(id)
click to toggle source
# File lib/student_progress/lesson.rb, line 17 def self.find_by_id(id) all.find {|l| l.id == id} end
new(attrs = {})
click to toggle source
# File lib/student_progress/lesson.rb, line 85 def initialize(attrs = {}) attrs.each do |attr, value| self.send("#{attr}=", value) end end
pre_cli()
click to toggle source
# File lib/student_progress/lesson.rb, line 21 def self.pre_cli pre_cli_end = nil StudentProgress::Lesson.all.each_with_index do |lesson, index| if lesson.id == 32164 pre_cli_end = index end end result = StudentProgress::Lesson.all[0..pre_cli_end] end
progress_when_topic_complete(topic_title)
click to toggle source
# File lib/student_progress/lesson.rb, line 80 def self.progress_when_topic_complete(topic_title) topic = StudentProgress::Topic.find_by_title(topic_title) progress_when_unit_complete(topic.units.last.title) end
progress_when_unit_complete(unit_title)
click to toggle source
# File lib/student_progress/lesson.rb, line 62 def self.progress_when_unit_complete(unit_title) lessons = 0 labs = 0 all.find do |lesson| lessons += 1 if lesson.content_type == "Lab" labs += 1 end # when the next lesson is on a different unit we're at the end lesson.unit.title == unit_title && all[lessons] && all[lessons].unit.title != unit_title end { goal: "Complete #{unit_title}", lessons: lessons, labs: labs } end
topic_from_lesson_title(lesson_title)
click to toggle source
# File lib/student_progress/lesson.rb, line 56 def self.topic_from_lesson_title(lesson_title) lesson = @@all.find{ |l| l.title.strip == lesson_title.strip} binding.pry unless lesson lesson ? lesson.unit.topic : "couldn't find that lesson" end
unit_from_lesson_title(lesson_title)
click to toggle source
# File lib/student_progress/lesson.rb, line 51 def self.unit_from_lesson_title(lesson_title) lesson = @@all.find{ |l| l.title == lesson_title} lesson ? lesson.unit.title : "couldn't find that lesson" end
Public Instance Methods
save()
click to toggle source
# File lib/student_progress/lesson.rb, line 91 def save @@all << self self end
topic()
click to toggle source
# File lib/student_progress/lesson.rb, line 96 def topic @unit && @unit.topic end
unit=(unit)
click to toggle source
# File lib/student_progress/lesson.rb, line 100 def unit=(unit) @unit = unit unit.add_lesson(self) @unit end