Sha256: 2601cdbe4c1bfc061455fee1194d0237bc3c0daa6fe31be636d78ec394a71dc1

Contents?: true

Size: 1.83 KB

Versions: 16

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

module DocTemplate
  module Objects
    class SectionsMetadata
      include Virtus.model
      include DocTemplate::Objects::TocHelpers

      class Section
        include Virtus.model
        include DocTemplate::Objects::MetadataHelpers

        attribute :children, Array[DocTemplate::Objects::ActivityMetadata::Activity]
        attribute :summary, String
        attribute :time, Integer, default: 0
        attribute :title, String
        attribute :template_type, String, default: 'core'

        # aliases to build toc
        attribute :handled, Boolean, default: false
        attribute :idx, Integer
        attribute :level, Integer, default: 1
        attribute :anchor, String, default: ->(a, _) { DocTemplate::Objects::MetadataHelpers.build_anchor_from(a) }

        attribute :material_ids, Array[Integer], default: []

        def add_activity(activity)
          self.time += activity.time.to_i
          activity.handled = true
          children << activity
        end

        def section_standard_info
          standard_info lesson_standard
        end
      end

      attribute :children, Array[Section]
      attribute :idx, Integer

      def self.build_from(data, template_type)
        copy = Marshal.load Marshal.dump(data)
        sections = copy.map do |metadata|
          metadata[:template_type] = template_type
          metadata[:summary] = DocTemplate.sanitizer.strip_html_element(metadata[:summary])
          metadata.transform_keys { |k| k.to_s.gsub('section-', '').underscore }
        end
        new(set_index(children: sections))
      end

      def add_break
        idx = children.index { |c| !c.handled } || -1
        section = Section.new(title: 'Foundational Skills Lesson', anchor: 'optbreak', time: 0, children: [])
        children.insert(idx - 1, section)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
lcms-engine-0.5.5 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.5.4 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.5.3 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.5.2 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.5.1 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.5.0 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.4.2 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.4.1 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.4.0 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.3.1 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.1.4 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.3.0 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.1.3 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.2.0 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.1.2 lib/doc_template/objects/sections_metadata.rb
lcms-engine-0.1.0 lib/doc_template/objects/sections_metadata.rb