Class: Lcms::Engine::PreviewsMaterialSerializer
- Inherits:
-
ActiveModel::Serializer
- Object
- ActiveModel::Serializer
- Lcms::Engine::PreviewsMaterialSerializer
- Defined in:
- app/serializers/lcms/engine/previews_material_serializer.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
- #activity ⇒ Object
- #color ⇒ Object
- #data ⇒ Object
- #for_group ⇒ Object
-
#initialize(props, document) ⇒ PreviewsMaterialSerializer
constructor
A new instance of PreviewsMaterialSerializer.
- #lesson ⇒ Object
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
#document ⇒ Object (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
#activity ⇒ Object
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 |
#color ⇒ Object
23 24 25 |
# File 'app/serializers/lcms/engine/previews_material_serializer.rb', line 23 def color @props['color'] end |
#data ⇒ Object
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_group ⇒ Object
38 39 40 |
# File 'app/serializers/lcms/engine/previews_material_serializer.rb', line 38 def for_group @props['group'] end |
#lesson ⇒ Object
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 |