Class: GovukNavigationHelpers::GroupedRelatedLinks
- Inherits:
-
Object
- Object
- GovukNavigationHelpers::GroupedRelatedLinks
- Defined in:
- lib/govuk_navigation_helpers/grouped_related_links.rb
Overview
Take a content item and group the related links according to an algorithm that is intended to display the related links into three groups, depending on how much they have in common with the main content item.
Instance Attribute Summary collapse
-
#content_item ⇒ Object
readonly
Returns the value of attribute content_item.
Instance Method Summary collapse
-
#initialize(content_item) ⇒ GroupedRelatedLinks
constructor
A new instance of GroupedRelatedLinks.
-
#parents_tagged_to_same_mainstream_browse_page ⇒ Object
This will return related items whose parents are tagged to the same mainstream browse page as the main content item’s parent.
-
#tagged_to_different_mainstream_browse_pages ⇒ Object
This will return related links that are tagged to mainstream browse pages unrelated to the main content item.
-
#tagged_to_same_mainstream_browse_page ⇒ Object
This will return related items that are tagged to the same mainstream browse page as the main content item.
Constructor Details
#initialize(content_item) ⇒ GroupedRelatedLinks
Returns a new instance of GroupedRelatedLinks.
10 11 12 |
# File 'lib/govuk_navigation_helpers/grouped_related_links.rb', line 10 def initialize(content_item) @content_item = content_item end |
Instance Attribute Details
#content_item ⇒ Object (readonly)
Returns the value of attribute content_item.
8 9 10 |
# File 'lib/govuk_navigation_helpers/grouped_related_links.rb', line 8 def content_item @content_item end |
Instance Method Details
#parents_tagged_to_same_mainstream_browse_page ⇒ Object
This will return related items whose parents are tagged to the same mainstream browse page as the main content item’s parent.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/govuk_navigation_helpers/grouped_related_links.rb', line 26 def parents_tagged_to_same_mainstream_browse_page return [] unless content_item.parent && content_item.parent.parent common_parent_content_ids = tagged_to_same_mainstream_browse_page.map(&:content_id) @parents_tagged_to_same_mainstream_browse_page ||= content_item..select do || next if common_parent_content_ids.include?(.content_id) .mainstream_browse_pages.map(&:parent).map(&:content_id).include?(content_item.parent.parent.content_id) end end |
#tagged_to_different_mainstream_browse_pages ⇒ Object
This will return related links that are tagged to mainstream browse pages unrelated to the main content item.
39 40 41 42 43 44 45 |
# File 'lib/govuk_navigation_helpers/grouped_related_links.rb', line 39 def tagged_to_different_mainstream_browse_pages all_content_ids = (tagged_to_same_mainstream_browse_page + parents_tagged_to_same_mainstream_browse_page).map(&:content_id) @tagged_to_different_mainstream_browse_pages ||= content_item..reject do || all_content_ids.include?(.content_id) end end |
#tagged_to_same_mainstream_browse_page ⇒ Object
This will return related items that are tagged to the same mainstream browse page as the main content item.
16 17 18 19 20 21 22 |
# File 'lib/govuk_navigation_helpers/grouped_related_links.rb', line 16 def tagged_to_same_mainstream_browse_page return [] unless content_item.parent @tagged_to_same_mainstream_browse_page ||= content_item..select do || .mainstream_browse_pages.map(&:content_id).include?(content_item.parent.content_id) end end |