Class: StudentProgress::Topic
- Inherits:
-
Object
- Object
- StudentProgress::Topic
- Defined in:
- lib/student_progress/topic.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#units ⇒ Object
readonly
Returns the value of attribute units.
Class Method Summary collapse
Instance Method Summary collapse
- #add_unit(unit) ⇒ Object
-
#initialize(attrs = {}) ⇒ Topic
constructor
A new instance of Topic.
- #lessons ⇒ Object
- #lessons_by_unit ⇒ Object
- #save ⇒ Object
- #summary ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Topic
Returns a new instance of Topic.
19 20 21 22 23 24 |
# File 'lib/student_progress/topic.rb', line 19 def initialize(attrs = {}) attrs.each do |attr, value| self.send("#{attr}=", value) end @units = [] end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'lib/student_progress/topic.rb', line 2 def id @id end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/student_progress/topic.rb', line 2 def title @title end |
#units ⇒ Object (readonly)
Returns the value of attribute units.
3 4 5 |
# File 'lib/student_progress/topic.rb', line 3 def units @units end |
Class Method Details
.all ⇒ Object
7 8 9 |
# File 'lib/student_progress/topic.rb', line 7 def self.all @@all end |
.create_from_hash(hash) ⇒ Object
11 12 13 |
# File 'lib/student_progress/topic.rb', line 11 def self.create_from_hash(hash) new(hash).save end |
.find_by_title(title) ⇒ Object
15 16 17 |
# File 'lib/student_progress/topic.rb', line 15 def self.find_by_title(title) all.find{|t| t.title == title} end |
Instance Method Details
#add_unit(unit) ⇒ Object
31 32 33 34 35 |
# File 'lib/student_progress/topic.rb', line 31 def add_unit(unit) @units << unit unless @units.include?(unit) unit.topic = self unless unit.topic == self unit end |
#lessons ⇒ Object
37 38 39 |
# File 'lib/student_progress/topic.rb', line 37 def lessons @units.map{|u| u.lessons}.flatten end |
#lessons_by_unit ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/student_progress/topic.rb', line 41 def lessons_by_unit result = {} @units.each do |unit| result[unit.title] = unit.lessons.map{|l| "#{l.title} - #{l.content_type} (#{l.id})"} end result end |
#save ⇒ Object
26 27 28 29 |
# File 'lib/student_progress/topic.rb', line 26 def save @@all << self self end |
#summary ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/student_progress/topic.rb', line 49 def summary { topic: title, units: @units.map{|u| u.title}, lessons: lessons_by_unit, 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 |