Sha256: 55ef81c5e363d0b9ed9b3541234c8eb2c37858c491b2d72d091600c39c26c0a8
Contents?: true
Size: 896 Bytes
Versions: 4
Compression:
Stored size: 896 Bytes
Contents
# frozen_string_literal: true require 'hs/loaders/xml_parser' module HS module CourseLoader include HS::XMLParser KNOWN_LOADERS = %i[title chapters].freeze def load_course(xml, &block) create_course(parse_xml(xml), &block) end private def create_course(data, &block) course = HS::Course.new(data.slice(:slug)) data[:_children].each { |child| load_a_part(course, child, &block) } course end def load_a_part(course, child, &block) return unless KNOWN_LOADERS.include?(child[:_name]) send("load_#{child[:_name]}", course, child, &block) end def load_title(course, child) course.title = get_text(child) end def load_chapters(course, child) return unless block_given? files = child[:_children].map { |c| c[:file] }.compact files.each { |file| yield course, file } end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
hs-cli-0.3.3 | lib/hs/loaders/course_loader.rb |
hs-cli-0.3.2 | lib/hs/loaders/course_loader.rb |
hs-cli-0.3.1 | lib/hs/loaders/course_loader.rb |
hs-cli-0.3.0 | lib/hs/loaders/course_loader.rb |