Class: Lcms::Engine::CurriculumResourceSerializer
- Inherits:
-
ActiveModel::Serializer
- Object
- ActiveModel::Serializer
- Lcms::Engine::CurriculumResourceSerializer
- Defined in:
- app/serializers/lcms/engine/curriculum_resource_serializer.rb
Instance Method Summary collapse
- #children ⇒ Object
- #descendants ⇒ Object
-
#initialize(object, options = {}) ⇒ CurriculumResourceSerializer
constructor
A new instance of CurriculumResourceSerializer.
- #lesson_count ⇒ Object
- #module? ⇒ Boolean
- #module_count ⇒ Object
- #module_sizes ⇒ Object
- #resource ⇒ Object
- #type ⇒ Object
- #unit_count ⇒ Object
- #unit_sizes ⇒ Object
Constructor Details
#initialize(object, options = {}) ⇒ CurriculumResourceSerializer
Returns a new instance of CurriculumResourceSerializer.
9 10 11 12 13 |
# File 'app/serializers/lcms/engine/curriculum_resource_serializer.rb', line 9 def initialize(object, = {}) super(object, ) @depth = [:depth] || 0 @depth_branch = [:depth_branch] end |
Instance Method Details
#children ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/serializers/lcms/engine/curriculum_resource_serializer.rb', line 23 def children return [] if !module? && @depth.zero? return [] if !module? && @depth_branch && !@depth_branch.include?(object.id) object.children .includes(:copyright_attributions) .eager_load(:standards) .ordered.map do |res| CurriculumResourceSerializer.new( res, depth: @depth - 1, depth_branch: @depth_branch ).as_json end end |
#descendants ⇒ Object
67 68 69 |
# File 'app/serializers/lcms/engine/curriculum_resource_serializer.rb', line 67 def descendants @descendants ||= object.self_and_descendants.ordered end |
#lesson_count ⇒ Object
39 40 41 42 |
# File 'app/serializers/lcms/engine/curriculum_resource_serializer.rb', line 39 def lesson_count count = descendants.select(&:lesson?).count object.assessment? ? count + 1 : count end |
#module? ⇒ Boolean
48 49 50 |
# File 'app/serializers/lcms/engine/curriculum_resource_serializer.rb', line 48 def module? type.casecmp('module').zero? end |
#module_count ⇒ Object
52 53 54 |
# File 'app/serializers/lcms/engine/curriculum_resource_serializer.rb', line 52 def module_count descendants.select(&:module?).count end |
#module_sizes ⇒ Object
56 57 58 |
# File 'app/serializers/lcms/engine/curriculum_resource_serializer.rb', line 56 def module_sizes descendants.select(&:module?).map { |r| r.self_and_descendants.lessons.count } end |
#resource ⇒ Object
15 16 17 |
# File 'app/serializers/lcms/engine/curriculum_resource_serializer.rb', line 15 def resource ResourceDetailsSerializer.new(object).as_json end |
#type ⇒ Object
19 20 21 |
# File 'app/serializers/lcms/engine/curriculum_resource_serializer.rb', line 19 def type object.curriculum_type end |
#unit_count ⇒ Object
44 45 46 |
# File 'app/serializers/lcms/engine/curriculum_resource_serializer.rb', line 44 def unit_count descendants.select(&:unit?).count end |
#unit_sizes ⇒ Object
60 61 62 63 64 65 |
# File 'app/serializers/lcms/engine/curriculum_resource_serializer.rb', line 60 def unit_sizes descendants.select(&:unit?).map do |r| count = r.self_and_descendants.lessons.count r.assessment? ? count + 1 : count end end |