# frozen_string_literal: true require 'hs/loaders/xml_parser' require 'hs/loaders/element_loader' module HS module ChapterLoader include HS::XMLParser include HS::ElementLoader def load_chapter(course, xml) create_chapter(course, parse_xml(xml)) end private def create_chapter(course, data) # rubocop:disable Metrics/MethodLength chapter = HS::Chapter.new( course, slug: data[:slug], review_status: data[:review_status] ) data[:_children].each do |child| case child[:_name] when :title chapter.title = get_text(child) when :intro chapter.intro = load_element(child) when :modules # TODO: extract :modules nil else element = load_element(child) chapter.content << element if element end end chapter end end end