Class: Lcms::Engine::PreviewsMaterialSerializer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(props, document) ⇒ PreviewsMaterialSerializer

Returns a new instance of PreviewsMaterialSerializer.



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

def initialize(props, document)
  super(document)
  @document = document
  @props = props
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



7
8
9
# File 'app/serializers/lcms/engine/previews_material_serializer.rb', line 7

def document
  @document
end

Instance Method Details

#activityObject



17
18
19
20
21
# File 'app/serializers/lcms/engine/previews_material_serializer.rb', line 17

def activity
  {}.tap do |x|
    %w(title type).each { |m| x["activity_#{m}"] = @props['activity'].send(:[], m) }
  end
end

#colorObject



23
24
25
# File 'app/serializers/lcms/engine/previews_material_serializer.rb', line 23

def color
  @props['color']
end

#dataObject



27
28
29
30
31
32
33
34
35
36
# File 'app/serializers/lcms/engine/previews_material_serializer.rb', line 27

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

#for_groupObject



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

def for_group
  @props['group']
end

#lessonObject



42
43
44
45
46
47
48
# File 'app/serializers/lcms/engine/previews_material_serializer.rb', line 42

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