Class: Lcms::Engine::ResourceInstructionSerializer

Inherits:
ActiveModel::Serializer
  • Object
show all
Includes:
ResourceHelper
Defined in:
app/serializers/lcms/engine/resource_instruction_serializer.rb

Instance Method Summary collapse

Methods included from ResourceHelper

#back_to_resource_path, #copyrights_text, #download_per_category_limit, #prerequisites_standards, #resource_breadcrumbs_with_links, #show_resource_path, #type_name

Instance Method Details

#grade_avgObject



38
39
40
# File 'app/serializers/lcms/engine/resource_instruction_serializer.rb', line 38

def grade_avg
  object.grades.average
end

#imgObject



30
31
32
# File 'app/serializers/lcms/engine/resource_instruction_serializer.rb', line 30

def img
  object.try(:image_file).try(:url) || placeholder
end

#instruction_typeObject



34
35
36
# File 'app/serializers/lcms/engine/resource_instruction_serializer.rb', line 34

def instruction_type
  media? ? object.resource_type : :generic
end

#pathObject



26
27
28
# File 'app/serializers/lcms/engine/resource_instruction_serializer.rb', line 26

def path
  media? ? media_path(object.id) : generic_path(object)
end

#subjectObject



18
19
20
# File 'app/serializers/lcms/engine/resource_instruction_serializer.rb', line 18

def subject
  object.subject.try(:downcase) || 'default'
end

#teaserObject



22
23
24
# File 'app/serializers/lcms/engine/resource_instruction_serializer.rb', line 22

def teaser
  object.title
end

#titleObject



11
12
13
14
15
16
# File 'app/serializers/lcms/engine/resource_instruction_serializer.rb', line 11

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