class GovukPublishingComponents::Presenters::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_publishing_components/presenters/content_item.rb, line 11 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_publishing_components/presenters/content_item.rb, line 127 def ==(other) content_id == other.content_id end
base_path()
click to toggle source
# File lib/govuk_publishing_components/presenters/content_item.rb, line 48 def base_path content_store_response.fetch("base_path") end
content_id()
click to toggle source
# File lib/govuk_publishing_components/presenters/content_item.rb, line 60 def content_id content_store_response.fetch("content_id") end
description()
click to toggle source
# File lib/govuk_publishing_components/presenters/content_item.rb, line 56 def description content_store_response.fetch("description", "") end
eql?(other)
click to toggle source
# File lib/govuk_publishing_components/presenters/content_item.rb, line 135 def eql?(other) self == other end
external_links()
click to toggle source
# File lib/govuk_publishing_components/presenters/content_item.rb, line 116 def external_links content_store_response.dig("details", "external_related_links").to_a end
hash()
click to toggle source
# File lib/govuk_publishing_components/presenters/content_item.rb, line 131 def hash content_id.hash end
mainstream_browse_pages()
click to toggle source
# File lib/govuk_publishing_components/presenters/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_publishing_components/presenters/content_item.rb, line 15 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_publishing_components/presenters/content_item.rb, line 22 def parent_taxon # TODO: Determine what to do when there are multiple taxons/parents. For # now just display the first of each. parent_taxons.min_by(&:title) end
parent_taxons()
click to toggle source
# File lib/govuk_publishing_components/presenters/content_item.rb, line 28 def parent_taxons @parent_taxons ||= taxon_links .select { |t| phase_is_live?(t) } .map { |taxon| ContentItem.new(taxon) }.sort_by(&:title) end
phase_is_live?(taxon)
click to toggle source
# File lib/govuk_publishing_components/presenters/content_item.rb, line 34 def phase_is_live?(taxon) taxon["phase"] == "live" end
quick_links()
click to toggle source
# File lib/govuk_publishing_components/presenters/content_item.rb, line 80 def quick_links content_store_response.dig("details", "quick_links").to_a end
title()
click to toggle source
# File lib/govuk_publishing_components/presenters/content_item.rb, line 44 def title content_store_response.fetch("title") end
url_override()
click to toggle source
# File lib/govuk_publishing_components/presenters/content_item.rb, line 52 def url_override content_store_response.dig("details", "url_override") end
Private Instance Methods
filter_link_type(links, type)
click to toggle source
# File lib/govuk_publishing_components/presenters/content_item.rb, line 148 def filter_link_type(links, type) links.select do |link| link["document_type"] == type end end
taxon_links()
click to toggle source
# File lib/govuk_publishing_components/presenters/content_item.rb, line 141 def taxon_links # A normal content item's taxon links are stored in ["links"]["taxons"] # whereas a Taxon content item's taxon links are stored in ["links"]["parent_taxons"] # so here we cater for both possibilities content_store_response.dig("links", "taxons") || content_store_response.dig("links", "parent_taxons") || [] end