Class: StudentProgress::Unit
- Inherits:
-
Object
- Object
- StudentProgress::Unit
- Defined in:
- lib/student_progress/unit.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#lessons ⇒ Object
readonly
Returns the value of attribute lessons.
-
#title ⇒ Object
Returns the value of attribute title.
-
#topic ⇒ Object
Returns the value of attribute topic.
Class Method Summary collapse
Instance Method Summary collapse
- #add_lesson(lesson) ⇒ Object
-
#initialize(attrs = {}) ⇒ Unit
constructor
A new instance of Unit.
- #lessons_by_type ⇒ Object
- #save ⇒ Object
- #summary ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Unit
Returns a new instance of Unit.
15 16 17 18 19 20 |
# File 'lib/student_progress/unit.rb', line 15 def initialize(attrs = {}) attrs.each do |attr, value| self.send("#{attr}=", value) end @lessons = [] end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'lib/student_progress/unit.rb', line 2 def id @id end |
#lessons ⇒ Object (readonly)
Returns the value of attribute lessons.
3 4 5 |
# File 'lib/student_progress/unit.rb', line 3 def lessons @lessons end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/student_progress/unit.rb', line 2 def title @title end |
#topic ⇒ Object
Returns the value of attribute topic.
2 3 4 |
# File 'lib/student_progress/unit.rb', line 2 def topic @topic end |
Class Method Details
.all ⇒ Object
7 8 9 |
# File 'lib/student_progress/unit.rb', line 7 def self.all @@all end |
.create_from_hash(hash) ⇒ Object
11 12 13 |
# File 'lib/student_progress/unit.rb', line 11 def self.create_from_hash(hash) new(hash).save end |
Instance Method Details
#add_lesson(lesson) ⇒ Object
27 28 29 30 31 |
# File 'lib/student_progress/unit.rb', line 27 def add_lesson(lesson) @lessons << lesson unless @lessons.include?(lesson) lesson.unit = self unless lesson.unit == self lesson end |
#lessons_by_type ⇒ Object
38 39 40 |
# File 'lib/student_progress/unit.rb', line 38 def lessons_by_type @lessons.map{|l| "#{l.title} - #{l.content_type} (#{l.id})"} end |
#save ⇒ Object
22 23 24 25 |
# File 'lib/student_progress/unit.rb', line 22 def save @@all << self self end |
#summary ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/student_progress/unit.rb', line 42 def summary { topic: topic, unit: title, lessons: lessons_by_type, readmes: @lessons.count{|l| l.content_type == "Readme"}, labs: @lessons.count{|l| l.content_type == "Lab"}, projects: @lessons.count{|l| l.content_type == "Project"} } end |