Class: HS::Chapter
- Inherits:
-
Object
- Object
- HS::Chapter
- Extended by:
- ChapterLoader
- Includes:
- ContentPreview, ReviewStatus
- Defined in:
- lib/hs/models/chapter.rb
Constant Summary
Constants included from ChapterLoader
HS::ChapterLoader::CUSTOM_LOADERS
Constants included from ReviewStatus
Constants included from ReviewStatusPreview
ReviewStatusPreview::REVIEW_COLOR, ReviewStatusPreview::REVIEW_ICON, ReviewStatusPreview::REVIEW_TITLE
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#course ⇒ Object
readonly
Returns the value of attribute course.
-
#intro ⇒ Object
Returns the value of attribute intro.
-
#modules ⇒ Object
readonly
Returns the value of attribute modules.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#title ⇒ Object
Returns the value of attribute title.
Attributes included from ReviewStatus
Class Method Summary collapse
-
.load(course, file) ⇒ Object
Loads chapter from file.
Instance Method Summary collapse
-
#find_module(slug) ⇒ Object
Tries to find module in this chapter by module slug.
-
#hs_url ⇒ Object
URL of this chapter when published.
-
#initialize(course, args) ⇒ Chapter
constructor
A new instance of Chapter.
Methods included from ChapterLoader
Methods included from ElementLoader
Methods included from XMLParser
Methods included from ContentPreview
Methods included from ReviewStatusPreview
#review_color, #review_icon, #review_title
Constructor Details
#initialize(course, args) ⇒ Chapter
Returns a new instance of Chapter.
26 27 28 29 30 31 32 33 34 |
# File 'lib/hs/models/chapter.rb', line 26 def initialize(course, args) @course = course @content = [] @modules = [] args.each do |key, val| instance_variable_set("@#{key}", val) end end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
23 24 25 |
# File 'lib/hs/models/chapter.rb', line 23 def content @content end |
#course ⇒ Object (readonly)
Returns the value of attribute course.
23 24 25 |
# File 'lib/hs/models/chapter.rb', line 23 def course @course end |
#intro ⇒ Object
Returns the value of attribute intro.
24 25 26 |
# File 'lib/hs/models/chapter.rb', line 24 def intro @intro end |
#modules ⇒ Object (readonly)
Returns the value of attribute modules.
23 24 25 |
# File 'lib/hs/models/chapter.rb', line 23 def modules @modules end |
#slug ⇒ Object
Returns the value of attribute slug.
24 25 26 |
# File 'lib/hs/models/chapter.rb', line 24 def slug @slug end |
#title ⇒ Object
Returns the value of attribute title.
24 25 26 |
# File 'lib/hs/models/chapter.rb', line 24 def title @title end |
Class Method Details
.load(course, file) ⇒ Object
Loads chapter from file.
14 15 16 17 18 19 20 21 |
# File 'lib/hs/models/chapter.rb', line 14 def self.load(course, file) dir = File.dirname(file) load_chapter(course, File.read(file)) do |chapter, module_file| path = "#{dir}/#{module_file}" chapter.modules << HS::Module.load(chapter, path) end end |
Instance Method Details
#find_module(slug) ⇒ Object
Tries to find module in this chapter by module slug.
37 38 39 |
# File 'lib/hs/models/chapter.rb', line 37 def find_module(slug) modules.find { |m| m.slug.to_s == slug.to_s } end |
#hs_url ⇒ Object
URL of this chapter when published.
42 43 44 |
# File 'lib/hs/models/chapter.rb', line 42 def hs_url "#{course.hs_url}/#{slug}" end |