Class: GovukNavigationHelpers::RummagerTaxonomySidebarLinks

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_navigation_helpers/rummager_taxonomy_sidebar_links.rb

Instance Method Summary collapse

Constructor Details

#initialize(content_item) ⇒ RummagerTaxonomySidebarLinks

Returns a new instance of RummagerTaxonomySidebarLinks.



3
4
5
# File 'lib/govuk_navigation_helpers/rummager_taxonomy_sidebar_links.rb', line 3

def initialize(content_item)
  @content_item = content_item
end

Instance Method Details



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/govuk_navigation_helpers/rummager_taxonomy_sidebar_links.rb', line 7

def related_items
  parent_taxons = @content_item.parent_taxons
  used_related_links = Set.new

  parent_taxons.each_with_index.map do |parent_taxon, index|
    related_content = index < 2 ? content_related_to(parent_taxon, used_related_links) : []

    used_related_links.merge(
      related_content.map { |content| content[:link] }
    )

    {
      title: parent_taxon.title,
      url: parent_taxon.base_path,
      description: parent_taxon.description,
      related_content: related_content,
    }
  end
end