Class: HS::Course
- Inherits:
-
Object
- Object
- HS::Course
- 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
-
#chapters ⇒ Object
readonly
Returns the value of attribute chapters.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
-
.load(file) ⇒ Object
Load course from given XML file.
Instance Method Summary collapse
-
#find_chapter(slug) ⇒ Object
Tries to find chapter in this course by chapter slug.
-
#hs_url ⇒ Object
URL of this course when published.
-
#initialize(args) ⇒ Course
constructor
A new instance of Course.
Methods included from CourseLoader
Methods included from XMLParser
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
#chapters ⇒ Object (readonly)
Returns the value of attribute chapters.
21 22 23 |
# File 'lib/hs/models/course.rb', line 21 def chapters @chapters end |
#slug ⇒ Object
Returns the value of attribute slug.
20 21 22 |
# File 'lib/hs/models/course.rb', line 20 def slug @slug end |
#title ⇒ Object
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_url ⇒ Object
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 |