Sha256: 8bd844482452616c3db9fb82ec5e82ed981b6b4131d736da23f8ab32f4d983ee
Contents?: true
Size: 1.35 KB
Versions: 2
Compression:
Stored size: 1.35 KB
Contents
# frozen_string_literal: true module Lcms module Engine class PreviewsMaterialSerializer < ActiveModel::Serializer attributes :activity, :color, :content_type, :data, :for_group, :lesson, :subject attr_reader :document delegate :content_type, :subject, to: :document def initialize(props, document) super(document) @document = document @props = props end def activity {}.tap do |x| %w(title type).each { |m| x["activity_#{m}"] = @props['activity'].send(:[], m) } end end def color @props['color'] end def data ordered_ids = @document.ordered_material_ids materials.to_a .sort_by { |m| ordered_ids.index(m.id) } .map do |material| MaterialSerializer.new( DocumentGenerator.material_presenter.new material, document: @document ).as_json end end def for_group @props['group'] end def lesson @lesson ||= {}.tap do |x| %i(grade ld_module subject title lesson).each { |m| x["lesson_#{m}"] = @document.send m } x['lesson_unit_topic'] = @document.topic end end private def materials @materials ||= Material.where(id: @props['material_ids']) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
lcms-engine-0.3.0 | app/serializers/lcms/engine/previews_material_serializer.rb |
lcms-engine-0.2.0 | app/serializers/lcms/engine/previews_material_serializer.rb |