Class: DatashiftJourney::JourneyReview

Inherits:
Object
  • Object
show all
Extended by:
PrepareDataForReview
Includes:
PrepareDataForReview
Defined in:
app/models/datashift_journey/journey_review.rb

Overview

This handles supplying data for a SUMMARY or REVIEW page or e.g. an email contaning a summary, usually as the key/value data, associated with an Enrollment state.

N.B - Our state engine collector the state of the journey (not essentially the state of the journey_plan), hence a state is more analogous to Page So here review data is assigned for DATA collected DURING a particular state - effectively the data saved during the UPDATE on that State

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(journey_plan, root_i18n_scope = '.journey_plan_review') ⇒ JourneyReview

This class can be reused anywhere that requires yaml-parsed summary data for an journey_plan. Hence the root_i18n_scope specifies the scope under which there must be a :common key at least. It is recommended that the root_i18n_scopeis a folder under a config/locales directory containing at least a common.en.yml file, and probably organisation- specific yml files too, which override common sections (see #prepare_review_data_list).



23
24
25
26
# File 'app/models/datashift_journey/journey_review.rb', line 23

def initialize(journey_plan, root_i18n_scope = '.journey_plan_review')
  @journey_plan = journey_plan
  @root_i18n_scope = root_i18n_scope
end

Instance Attribute Details

#journey_planObject (readonly)

Returns the value of attribute journey_plan.



15
16
17
# File 'app/models/datashift_journey/journey_review.rb', line 15

def journey_plan
  @journey_plan
end

#root_i18n_scopeObject (readonly)

Returns the value of attribute root_i18n_scope.



15
16
17
# File 'app/models/datashift_journey/journey_review.rb', line 15

def root_i18n_scope
  @root_i18n_scope
end

Instance Method Details

#prepare_review_data_listObject

Merge common ‘sections’ in the review data with any app-specific sections; if an app-specific section matches by heading (title) then it replaces the standard one. In this way apps can override discrete sections in the summary data.



33
34
35
36
37
38
39
40
41
# File 'app/models/datashift_journey/journey_review.rb', line 33

def prepare_review_data_list
  merged_sections = common_sections.each_with_index do |common_section, idx|
    replacement = organisation_specific_sections.find do |org_specific_section|
      org_specific_section.heading == common_section.heading
    end
    common_sections[idx] = replacement if replacement
  end
  merged_sections
end