Sha256: a992eca39edf95c650d513b59551093d6a990e5abf6a4f95571375c2bd95af96

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true
module ThinkFeelDoEngine
  module Reports
    # Shared Lesson Module behavior.
    module LessonModule
      URL_ROOT_RE = /^[^\/]*\/\/[^\/]+/
      # Disabling method length due to nested methods.
      # rubocop:disable Metrics/MethodLength,Lint/NestedMethodDefinition
      def self.included(klass)
        class << klass
          # Returns a hash mapping lesson entry (first slide) path to Lesson
          # Module id.
          def lesson_entries_map
            lessons = ContentModules::LessonModule
                      .includes(:content_providers).map do |m|
              first_provider_id = m.provider(1).try(:id)
              next unless first_provider_id
              path = navigator_location_path(module_id: m.id,
                                             provider_id: first_provider_id,
                                             content_position: 1)
              [path, m.id]
            end.compact

            Hash[lessons]
          end

          # Returns a hash mapping path to Lesson Module id.
          def lessons_map
            lessons = ContentModules::LessonModule.all.map do |m|
              path = navigator_location_path(module_id: m.id)

              [path, m.id]
            end

            Hash[lessons]
          end

          private

          def navigator_location_path(options)
            ThinkFeelDoEngine::Engine.routes.url_helpers
                                     .navigator_location_path(options)
          end
        end
      end
      # rubocop:enable Metrics/LineLength,Lint/NestedMethodDefinition
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
think_feel_do_engine-3.21.0 app/models/think_feel_do_engine/reports/lesson_module.rb
think_feel_do_engine-3.20.1 app/models/think_feel_do_engine/reports/lesson_module.rb