Class: HS::Course

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

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

Methods included from CoursePreview

#preview, #save_preview

Methods included from HTMLPreview

#html_preview

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)
  args.each do |key, val|
    instance_variable_set("@#{key}", val)
  end

  @chapters = []
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



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



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

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

#hs_urlObject



35
36
37
# File 'lib/hs/models/course.rb', line 35

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