Class: StudentProgress::Lesson
- Inherits:
-
Object
- Object
- StudentProgress::Lesson
- Defined in:
- lib/student_progress/lesson.rb
Constant Summary collapse
- SECTIONS =
{}
- @@all =
[]
Instance Attribute Summary collapse
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#id ⇒ Object
Returns the value of attribute id.
-
#repo ⇒ Object
Returns the value of attribute repo.
-
#title ⇒ Object
Returns the value of attribute title.
-
#unit ⇒ Object
Returns the value of attribute unit.
Class Method Summary collapse
- .all ⇒ Object
- .build_section_hash ⇒ Object
- .create_from_hash(hash) ⇒ Object
- .find_by_id(id) ⇒ Object
- .pre_cli ⇒ Object
- .progress_when_topic_complete(topic_title) ⇒ Object
- .progress_when_unit_complete(unit_title) ⇒ Object
- .topic_from_lesson_title(lesson_title) ⇒ Object
- .unit_from_lesson_title(lesson_title) ⇒ Object
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Lesson
constructor
A new instance of Lesson.
- #save ⇒ Object
- #topic ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Lesson
Returns a new instance of Lesson.
85 86 87 88 89 |
# File 'lib/student_progress/lesson.rb', line 85 def initialize(attrs = {}) attrs.each do |attr, value| self.send("#{attr}=", value) end end |
Instance Attribute Details
#content_type ⇒ Object
Returns the value of attribute content_type.
2 3 4 |
# File 'lib/student_progress/lesson.rb', line 2 def content_type @content_type end |
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'lib/student_progress/lesson.rb', line 2 def id @id end |
#repo ⇒ Object
Returns the value of attribute repo.
2 3 4 |
# File 'lib/student_progress/lesson.rb', line 2 def repo @repo end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/student_progress/lesson.rb', line 2 def title @title end |
#unit ⇒ Object
Returns the value of attribute unit.
3 4 5 |
# File 'lib/student_progress/lesson.rb', line 3 def unit @unit end |
Class Method Details
.all ⇒ Object
9 10 11 |
# File 'lib/student_progress/lesson.rb', line 9 def self.all @@all end |
.build_section_hash ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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) ⇒ Object
13 14 15 |
# File 'lib/student_progress/lesson.rb', line 13 def self.create_from_hash(hash) new(hash).save end |
.find_by_id(id) ⇒ Object
17 18 19 |
# File 'lib/student_progress/lesson.rb', line 17 def self.find_by_id(id) all.find {|l| l.id == id} end |
.pre_cli ⇒ Object
21 22 23 24 25 26 27 28 29 |
# 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) ⇒ Object
80 81 82 83 |
# 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) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# 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) ⇒ Object
56 57 58 59 60 |
# 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) ⇒ Object
51 52 53 54 |
# 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 |
Instance Method Details
#save ⇒ Object
91 92 93 94 |
# File 'lib/student_progress/lesson.rb', line 91 def save @@all << self self end |
#topic ⇒ Object
96 97 98 |
# File 'lib/student_progress/lesson.rb', line 96 def topic @unit && @unit.topic end |