Sha256: df9d5f55f4a4fa0f5f2a4117a62cfb6b234306698be63cb785edf54436a48f66
Contents?: true
Size: 1.33 KB
Versions: 16
Compression:
Stored size: 1.33 KB
Contents
# frozen_string_literal: true module Lcms module Engine class RelatedInstructionsService attr_reader :resource, :expanded, :has_more, :instructions def initialize(resource, expanded) @resource = resource @expanded = expanded find_related_instructions end private def find_related_instructions instructions = expanded ? expanded_instructions : colapsed_instructions @has_more = true if videos.size > instructions.size @instructions = instructions.map do |inst| ResourceInstructionSerializer.new(inst) end end def expanded_instructions videos end def colapsed_instructions # show 4 videos videos[0...4] end def videos @videos ||= find_related_through_standards(limit: 4) do |standard| standard.resources.media.distinct end end def find_related_through_standards(limit:, &_block) related = resource.standards.flat_map do |standard| qset = yield standard qset = qset.limit(limit) unless expanded # limit each part qset end.uniq if expanded related else @has_more = true if related.count > limit related[0...limit] # limit total end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems