learningtapestry/lcms-engine

View on GitHub
lib/doc_template/document_toc.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

module DocTemplate
  class DocumentToc
    REGISTERED_METADATA = %i(agenda sections).freeze
    private_constant :REGISTERED_METADATA

    #
    # Build the ToC from the first available metadata.
    # We're doing that to allow cross-subject data passing.
    #
    def self.parse(opts = {})
      metadata = REGISTERED_METADATA.detect { |m| opts[m]&.children.present? }
      Objects::TocMetadata.new opts[metadata]
    end
  end
end