class GovukNavigationHelpers::ContentItem

Simple wrapper around a content store representation of a content item. Works for both the main content item and the expanded links in the links hash.

@private

Attributes

content_store_response[R]

Public Class Methods

new(content_store_response) click to toggle source
# File lib/govuk_navigation_helpers/content_item.rb, line 10
def initialize(content_store_response)
  @content_store_response = content_store_response.to_h
end

Public Instance Methods

==(other) click to toggle source
# File lib/govuk_navigation_helpers/content_item.rb, line 127
def ==(other)
  content_id == other.content_id
end
base_path() click to toggle source
# File lib/govuk_navigation_helpers/content_item.rb, line 48
def base_path
  content_store_response.fetch("base_path")
end
content_id() click to toggle source
# File lib/govuk_navigation_helpers/content_item.rb, line 56
def content_id
  content_store_response.fetch("content_id")
end
description() click to toggle source
# File lib/govuk_navigation_helpers/content_item.rb, line 52
def description
  content_store_response.fetch("description", "")
end
eql?(other) click to toggle source
# File lib/govuk_navigation_helpers/content_item.rb, line 135
def eql?(other)
  self == other
end
hash() click to toggle source
# File lib/govuk_navigation_helpers/content_item.rb, line 131
def hash
  content_id.hash
end
mainstream_browse_pages() click to toggle source
# File lib/govuk_navigation_helpers/content_item.rb, line 38
def mainstream_browse_pages
  content_store_response.dig("links", "mainstream_browse_pages").to_a.map do |link|
    ContentItem.new(link)
  end
end
parent() click to toggle source
# File lib/govuk_navigation_helpers/content_item.rb, line 14
def parent
  parent_item = content_store_response.dig("links", "parent", 0)
  return unless parent_item
  ContentItem.new(parent_item)
end
parent_taxon() click to toggle source
# File lib/govuk_navigation_helpers/content_item.rb, line 20
def parent_taxon
  # TODO: Determine what to do when there are multiple taxons/parents. For
  # now just display the first of each.
  parent_taxons.sort_by(&:title).first
end
parent_taxons() click to toggle source
# File lib/govuk_navigation_helpers/content_item.rb, line 26
def parent_taxons
  @_parent_taxons ||= begin
    taxon_links
      .select { |t| phase_is_live?(t) }
      .map { |taxon| ContentItem.new(taxon) }.sort_by(&:title)
  end
end
phase_is_live?(taxon) click to toggle source
# File lib/govuk_navigation_helpers/content_item.rb, line 34
def phase_is_live?(taxon)
  taxon["phase"] == "live"
end
title() click to toggle source
# File lib/govuk_navigation_helpers/content_item.rb, line 44
def title
  content_store_response.fetch("title")
end

Private Instance Methods