Class: HS::Course

Inherits:
Object
  • Object
show all
Extended by:
CourseLoader
Defined in:
lib/hs/models/course.rb

Overview

Course is a top level model for a course.

Constant Summary

Constants included from CourseLoader

HS::CourseLoader::KNOWN_LOADERS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CourseLoader

load_course

Methods included from XMLParser

#get_text, #parse_xml

Constructor Details

#initialize(args) ⇒ Course

Returns a new instance of Course.



23
24
25
26
27
28
29
# File 'lib/hs/models/course.rb', line 23

def initialize(args)
  @chapters = []

  args.each do |key, val|
    instance_variable_set("@#{key}", val)
  end
end

Instance Attribute Details

#chaptersObject (readonly)

Returns the value of attribute chapters.



21
22
23
# File 'lib/hs/models/course.rb', line 21

def chapters
  @chapters
end

#slugObject

Returns the value of attribute slug.



20
21
22
# File 'lib/hs/models/course.rb', line 20

def slug
  @slug
end

#titleObject

Returns the value of attribute title.



20
21
22
# File 'lib/hs/models/course.rb', line 20

def title
  @title
end

Class Method Details

.load(file) ⇒ Object

Load course from given XML file.



11
12
13
14
15
16
17
18
# File 'lib/hs/models/course.rb', line 11

def self.load(file)
  dir = File.dirname(file)

  load_course(File.read(file)) do |course, chapter_file|
    path = "#{dir}/#{chapter_file}"
    course.chapters << HS::Chapter.load(course, path)
  end
end

Instance Method Details

#find_chapter(slug) ⇒ Object

Tries to find chapter in this course by chapter slug.



32
33
34
# File 'lib/hs/models/course.rb', line 32

def find_chapter(slug)
  chapters.find { |c| c.slug.to_s == slug.to_s }
end

#hs_urlObject

URL of this course when published.



37
38
39
# File 'lib/hs/models/course.rb', line 37

def hs_url
  "#{HS::Config.publish_url}/learn/#{slug}"
end