Sha256: 96a722bbe5eb3fee1ba7e767659dda78fb71c4cbb840b090277922abccef80d1

Contents?: true

Size: 918 Bytes

Versions: 4

Compression:

Stored size: 918 Bytes

Contents

# frozen_string_literal: true

require 'hs/loaders/course_loader'

module HS
  # {HS::Course} is a top level model for a course.
  class Course
    extend HS::CourseLoader

    # Load course from given XML file.
    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

    attr_accessor :slug, :title
    attr_reader :chapters

    def initialize(args)
      @chapters = []

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

    # Tries to find chapter in this course by chapter slug.
    def find_chapter(slug)
      chapters.find { |c| c.slug.to_s == slug.to_s }
    end

    # URL of this course when published.
    def hs_url
      "#{HS::Config.publish_url}/learn/#{slug}"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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