Class: Lcms::Engine::HierarchicalPosition

Inherits:
Object
  • Object
show all
Defined in:
app/entities/lcms/engine/hierarchical_position.rb

Constant Summary collapse

RESOURCE_TYPE_ORDER =
%w(resource media quick_reference_guide text_set).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ HierarchicalPosition

Returns a new instance of HierarchicalPosition.



10
11
12
# File 'app/entities/lcms/engine/hierarchical_position.rb', line 10

def initialize(resource)
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



8
9
10
# File 'app/entities/lcms/engine/hierarchical_position.rb', line 8

def resource
  @resource
end

Instance Method Details

#positionObject

Position mask:

  • We use 7 blocks of 2 numbers for:

    subject, resource_types, grades (average if more than one), module, unit,
    lesson, num_of_grades
    
  • The last position is the number of different grades covered, i.e: a resource with 3 different grades show after one with 2, (more specific at the top, more generic at the bottom)



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/entities/lcms/engine/hierarchical_position.rb', line 21

def position
  return default_position if dettached_resource?

  [
    subject_position, # subject
    resource_type_position, # resource_type
    resource.grades.average_number, # grades
    module_position, # module
    unit_position, # unit
    lesson_position, # lesson
    resource.grades.list.size # number of grades
  ].map { |v| v.to_s.rjust(2, '0') }.join(' ')
end