Class: HS::Chapter

Inherits:
Object
  • Object
show all
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

ReviewStatus::REVIEW_STATUSES

Constants included from ReviewStatusPreview

ReviewStatusPreview::REVIEW_COLOR, ReviewStatusPreview::REVIEW_ICON, ReviewStatusPreview::REVIEW_TITLE

Instance Attribute Summary collapse

Attributes included from ReviewStatus

#review_status

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ChapterLoader

load_chapter

Methods included from ElementLoader

#load_element, #load_elements

Methods included from XMLParser

#get_text, #parse_xml

Methods included from ContentPreview

#preview

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

#contentObject (readonly)

Returns the value of attribute content.



23
24
25
# File 'lib/hs/models/chapter.rb', line 23

def content
  @content
end

#courseObject (readonly)

Returns the value of attribute course.



23
24
25
# File 'lib/hs/models/chapter.rb', line 23

def course
  @course
end

#introObject

Returns the value of attribute intro.



24
25
26
# File 'lib/hs/models/chapter.rb', line 24

def intro
  @intro
end

#modulesObject (readonly)

Returns the value of attribute modules.



23
24
25
# File 'lib/hs/models/chapter.rb', line 23

def modules
  @modules
end

#slugObject

Returns the value of attribute slug.



24
25
26
# File 'lib/hs/models/chapter.rb', line 24

def slug
  @slug
end

#titleObject

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_urlObject

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