Class: Lcms::Engine::DocumentMaterialSerializer

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

Instance Method Summary collapse

Constructor Details

#initialize(document, materials) ⇒ DocumentMaterialSerializer

Returns a new instance of DocumentMaterialSerializer.



8
9
10
11
12
# File 'app/serializers/lcms/engine/document_material_serializer.rb', line 8

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

Instance Method Details

#dataObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/serializers/lcms/engine/document_material_serializer.rb', line 14

def data
  ordered_ids = @document.ordered_material_ids
  anchors = @document.materials_anchors
  @materials
    .sort_by { |m| ordered_ids.index(m.id) }
    .map do |material|
    MaterialSerializer.new(
      DocumentGenerator.material_presenter.new material, document: @document, anchors: anchors[material.id] || []
    ).as_json
  end
end