Class: GovukNavigationHelpers::ContentItem
- Inherits:
-
Object
- Object
- GovukNavigationHelpers::ContentItem
- Defined in:
- lib/govuk_navigation_helpers/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.
Constant Summary collapse
- WORLD_TAXON_CONTENT_ID =
"91b8ef20-74e7-4552-880c-50e6d73c2ff9".freeze
- EDUCATION_TAXON_CONTENT_ID =
"c58fdadd-7743-46d6-9629-90bb3ccc4ef0".freeze
- CHILDCARE_PARENTING_TAXON_CONTENT_ID =
"206b7f3a-49b5-476f-af0f-fd27e2a68473".freeze
Instance Attribute Summary collapse
-
#content_store_response ⇒ Object
readonly
Returns the value of attribute content_store_response.
Class Method Summary collapse
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
- #quick_links ⇒ Object
- #related_collections ⇒ Object
- #related_links ⇒ Object
- #related_ordered_items ⇒ Object
- #related_organisations ⇒ Object
- #related_other_contacts ⇒ Object
- #related_policies ⇒ Object
- #related_statistical_data_sets ⇒ Object
- #related_topical_events ⇒ Object
- #related_topics ⇒ Object
- #related_world_locations ⇒ Object
- #related_worldwide_organisations ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(content_store_response) ⇒ ContentItem
Returns a new instance of ContentItem.
22 23 24 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 22 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.
20 21 22 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 20 def content_store_response @content_store_response end |
Class Method Details
.whitelisted_root_taxon_content_ids ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 12 def self.whitelisted_root_taxon_content_ids [ WORLD_TAXON_CONTENT_ID, EDUCATION_TAXON_CONTENT_ID, CHILDCARE_PARENTING_TAXON_CONTENT_ID, ] end |
Instance Method Details
#==(other) ⇒ Object
135 136 137 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 135 def ==(other) content_id == other.content_id end |
#as_taxonomy_sidebar_link ⇒ Object
128 129 130 131 132 133 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 128 def { title: title, link: base_path, } end |
#base_path ⇒ Object
56 57 58 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 56 def base_path content_store_response.fetch("base_path") end |
#content_id ⇒ Object
64 65 66 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 64 def content_id content_store_response.fetch("content_id") end |
#curated_taxonomy_sidebar_links ⇒ Object
74 75 76 77 78 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 74 def content_store_response.dig("links", "ordered_related_items_overrides").to_a.map do |link| ContentItem.new(link) end end |
#description ⇒ Object
60 61 62 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 60 def description content_store_response.fetch("description", "") end |
#eql?(other) ⇒ Boolean
143 144 145 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 143 def eql?(other) self == other end |
#external_links ⇒ Object
124 125 126 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 124 def external_links content_store_response.dig("details", "external_related_links").to_a end |
#hash ⇒ Object
139 140 141 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 139 def hash content_id.hash end |
#mainstream_browse_pages ⇒ Object
46 47 48 49 50 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 46 def mainstream_browse_pages content_store_response.dig("links", "mainstream_browse_pages").to_a.map do |link| ContentItem.new(link) end end |
#parent ⇒ Object
26 27 28 29 30 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 26 def parent parent_item = content_store_response.dig("links", "parent", 0) return unless parent_item ContentItem.new(parent_item) end |
#parent_taxon ⇒ Object
32 33 34 35 36 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 32 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 ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 38 def parent_taxons @_parent_taxons ||= begin taxon_links .select { |t| descendent_from_whitelisted_root_taxon?(t) } .map { |taxon| ContentItem.new(taxon) }.sort_by(&:title) end end |
#quick_links ⇒ Object
84 85 86 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 84 def quick_links content_store_response.dig("details", "quick_links").to_a end |
#related_collections ⇒ Object
88 89 90 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 88 def filter_link_type(content_store_response.dig("links", "document_collections").to_a, "document_collection") end |
#related_links ⇒ Object
68 69 70 71 72 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 68 def content_store_response.dig("links", "ordered_related_items").to_a.map do |link| ContentItem.new(link) end end |
#related_ordered_items ⇒ Object
80 81 82 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 80 def content_store_response.dig("links", "ordered_related_items").to_a end |
#related_organisations ⇒ Object
96 97 98 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 96 def filter_link_type(content_store_response.dig("links", "organisations").to_a, "organisation") end |
#related_other_contacts ⇒ Object
92 93 94 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 92 def filter_link_type(content_store_response.dig("links", "related").to_a, "contact") end |
#related_policies ⇒ Object
100 101 102 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 100 def filter_link_type(content_store_response.dig("links", "related_policies").to_a, "policy") end |
#related_statistical_data_sets ⇒ Object
104 105 106 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 104 def filter_link_type(content_store_response.dig("links", "related_statistical_data_sets").to_a, "statistical_data_set") end |
#related_topical_events ⇒ Object
112 113 114 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 112 def filter_link_type(content_store_response.dig("links", "topical_events").to_a, "topical_event") end |
#related_topics ⇒ Object
108 109 110 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 108 def filter_link_type(content_store_response.dig("links", "topics").to_a, "topic") end |
#related_world_locations ⇒ Object
116 117 118 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 116 def content_store_response.dig("links", "world_locations").to_a end |
#related_worldwide_organisations ⇒ Object
120 121 122 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 120 def filter_link_type(content_store_response.dig("links", "worldwide_organisations").to_a, "worldwide_organisation") end |
#title ⇒ Object
52 53 54 |
# File 'lib/govuk_navigation_helpers/content_item.rb', line 52 def title content_store_response.fetch("title") end |