Sha256: 0115f8ab8fd637d6b2f06da86a482af1f9266afcb9274a3e908a6d852ae3108e
Contents?: true
Size: 1.11 KB
Versions: 12
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true module Lcms module Engine class ResourceInstructionSerializer < ActiveModel::Serializer include ResourceHelper attributes :id, :title, :subject, :teaser, :path, :img, :instruction_type, :grade_avg, :time_to_teach def title return object.title if media? type_name = I18n.t("resource_types.#{object.resource_type}") object.grades.present? ? "#{object.grades.to_str} #{type_name}" : type_name end def subject object.subject.try(:downcase) || 'default' end def teaser object.title end def path media? ? media_path(object.id) : generic_path(object) end def img object.try(:image_file).try(:url) || placeholder end def instruction_type media? ? object.resource_type : :generic end def grade_avg object.grades.average end private def media? object.media? end def placeholder ActionController::Base.helpers.image_path('resource_placeholder.jpg') end end end end
Version data entries
12 entries across 12 versions & 1 rubygems