Sha256: 365b0fbee87d3fdf6ba1fcdffc8e13ff71e20c0f0d414f6981544ebf3da303c0

Contents?: true

Size: 1.13 KB

Versions: 16

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Lcms
  module Engine
    class CurriculumMap
      attr_reader :resource

      def initialize(resource)
        @resource = resource
      end

      def props
        return {} unless resource.present?

        { active: active_branch, results: curriculum }
      end

      private

      def full_depth?
        @full_depth ||= resource.lesson? || resource.unit? || resource.module?
      end

      def active_branch
        @active_branch ||= resource.self_and_ancestor_ids
      end

      def target_branch
        if full_depth?
          mod = resource.parents.detect(&:module?)
          mod ? mod.children.ids : []
        else
          []
        end
      end

      def curriculum
        grade = resource.ancestors
                  .includes(:copyright_attributions)
                  .eager_load(:standards)
                  .where(curriculum_type: :grade)
                  .take
        CurriculumResourceSerializer.new(
          grade,
          depth: full_depth? ? Resource.hierarchy.size : 1,
          depth_branch: active_branch + target_branch
        ).as_json
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
lcms-engine-0.5.5 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.5.4 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.5.3 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.5.2 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.5.1 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.5.0 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.4.2 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.4.1 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.4.0 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.3.1 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.1.4 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.3.0 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.1.3 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.2.0 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.1.2 app/entities/lcms/engine/curriculum_map.rb
lcms-engine-0.1.0 app/entities/lcms/engine/curriculum_map.rb