Sha256: 5da27cb0fd17db2788588de21ac0c646e5625d661c895072a3ba2623db6cb02f

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'hs/loaders/chapter_loader'
require 'hs/preview/content_preview'
require 'hs/models/review_status'

module HS
  class Chapter
    extend HS::ChapterLoader
    include HS::ContentPreview
    include HS::ReviewStatus

    # Loads chapter from file.
    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

    attr_reader :course, :content, :modules
    attr_accessor :slug, :title, :intro

    def initialize(course, args)
      @course = course
      @content = []
      @modules = []

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

    # Tries to find module in this chapter by module slug.
    def find_module(slug)
      modules.find { |m| m.slug.to_s == slug.to_s }
    end

    # URL of this chapter when published.
    def hs_url
      "#{course.hs_url}/#{slug}"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hs-cli-0.3.3 lib/hs/models/chapter.rb
hs-cli-0.3.2 lib/hs/models/chapter.rb
hs-cli-0.3.1 lib/hs/models/chapter.rb
hs-cli-0.3.0 lib/hs/models/chapter.rb