Class: GovukPublishingComponents::Presenters::ContentItem
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::ContentItem
- Defined in:
- lib/govuk_publishing_components/presenters/content_item.rb
Overview
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.
Instance Attribute Summary collapse
-
#content_store_response ⇒ Object
readonly
Returns the value of attribute content_store_response.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as_taxonomy_sidebar_link ⇒ Object
- #base_path ⇒ Object
- #content_id ⇒ Object
- #curated_taxonomy_sidebar_links ⇒ Object
- #description ⇒ Object
- #eql?(other) ⇒ Boolean
- #external_links ⇒ Object
- #hash ⇒ Object
-
#initialize(content_store_response) ⇒ ContentItem
constructor
A new instance of ContentItem.
- #mainstream_browse_pages ⇒ Object
- #parent ⇒ Object
- #parent_taxon ⇒ Object
- #parent_taxons ⇒ Object
- #phase_is_live?(taxon) ⇒ Boolean
- #quick_links ⇒ Object
- #related_collections ⇒ Object
- #related_links ⇒ Object
- #related_ordered_items ⇒ Object
- #related_organisations ⇒ Object
- #related_other_contacts ⇒ Object
- #related_statistical_data_sets ⇒ Object
- #related_topical_events ⇒ Object
- #related_world_locations ⇒ Object
- #related_worldwide_organisations ⇒ Object
- #title ⇒ Object
- #url_override ⇒ Object
Constructor Details
#initialize(content_store_response) ⇒ ContentItem
Returns a new instance of ContentItem.
11 12 13 |
# 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 |
Instance Attribute Details
#content_store_response ⇒ Object (readonly)
Returns the value of attribute content_store_response.
9 10 11 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 9 def content_store_response @content_store_response end |
Instance Method Details
#==(other) ⇒ Object
123 124 125 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 123 def ==(other) content_id == other.content_id end |
#as_taxonomy_sidebar_link ⇒ Object
116 117 118 119 120 121 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 116 def { title:, link: base_path, } end |
#base_path ⇒ Object
48 49 50 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 48 def base_path content_store_response.fetch("base_path") end |
#content_id ⇒ Object
60 61 62 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 60 def content_id content_store_response.fetch("content_id") end |
#curated_taxonomy_sidebar_links ⇒ Object
70 71 72 73 74 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 70 def content_store_response.dig("links", "ordered_related_items_overrides").to_a.map do |link| ContentItem.new(link) end end |
#description ⇒ Object
56 57 58 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 56 def description content_store_response.fetch("description", "") end |
#eql?(other) ⇒ Boolean
131 132 133 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 131 def eql?(other) self == other end |
#external_links ⇒ Object
112 113 114 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 112 def external_links content_store_response.dig("details", "external_related_links").to_a end |
#hash ⇒ Object
127 128 129 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 127 def hash content_id.hash end |
#mainstream_browse_pages ⇒ Object
38 39 40 41 42 |
# 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 ⇒ Object
15 16 17 18 19 20 |
# 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 ⇒ Object
22 23 24 25 26 |
# 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 ⇒ Object
28 29 30 31 32 |
# 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) ⇒ Boolean
34 35 36 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 34 def phase_is_live?(taxon) taxon["phase"] == "live" end |
#quick_links ⇒ Object
80 81 82 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 80 def quick_links content_store_response.dig("details", "quick_links").to_a end |
#related_collections ⇒ Object
84 85 86 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 84 def filter_link_type(content_store_response.dig("links", "document_collections").to_a, "document_collection") end |
#related_links ⇒ Object
64 65 66 67 68 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 64 def content_store_response.dig("links", "ordered_related_items").to_a.map do |link| ContentItem.new(link) end end |
#related_ordered_items ⇒ Object
76 77 78 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 76 def content_store_response.dig("links", "ordered_related_items").to_a end |
#related_organisations ⇒ Object
92 93 94 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 92 def filter_link_type(content_store_response.dig("links", "organisations").to_a, "organisation") end |
#related_other_contacts ⇒ Object
88 89 90 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 88 def filter_link_type(content_store_response.dig("links", "related").to_a, "contact") end |
#related_statistical_data_sets ⇒ Object
96 97 98 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 96 def filter_link_type(content_store_response.dig("links", "related_statistical_data_sets").to_a, "statistical_data_set") end |
#related_topical_events ⇒ Object
100 101 102 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 100 def filter_link_type(content_store_response.dig("links", "topical_events").to_a, "topical_event") end |
#related_world_locations ⇒ Object
104 105 106 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 104 def content_store_response.dig("links", "world_locations").to_a end |
#related_worldwide_organisations ⇒ Object
108 109 110 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 108 def filter_link_type(content_store_response.dig("links", "worldwide_organisations").to_a, "worldwide_organisation") end |
#title ⇒ Object
44 45 46 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 44 def title content_store_response.fetch("title") end |
#url_override ⇒ Object
52 53 54 |
# File 'lib/govuk_publishing_components/presenters/content_item.rb', line 52 def url_override content_store_response.dig("details", "url_override") end |