class StudentProgress::Unit

Attributes

id[RW]
lessons[R]
title[RW]
topic[RW]

Public Class Methods

all() click to toggle source
# File lib/student_progress/unit.rb, line 7
def self.all
  @@all
end
create_from_hash(hash) click to toggle source
# File lib/student_progress/unit.rb, line 11
def self.create_from_hash(hash)
  new(hash).save
end
new(attrs = {}) click to toggle source
# File lib/student_progress/unit.rb, line 15
def initialize(attrs = {})
  attrs.each do |attr, value|
    self.send("#{attr}=", value)
  end
  @lessons = []
end

Public Instance Methods

add_lesson(lesson) click to toggle source
# 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() click to toggle source
# File lib/student_progress/unit.rb, line 38
def lessons_by_type
  @lessons.map{|l| "#{l.title} - #{l.content_type} (#{l.id})"}
end
save() click to toggle source
# File lib/student_progress/unit.rb, line 22
def save 
  @@all << self 
  self
end
summary() click to toggle source
# 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
topic=(topic) click to toggle source
# File lib/student_progress/unit.rb, line 33
def topic=(topic)
  @topic = topic
  topic.add_unit(self)
end