Class: GovukPublishingComponents::Presenters::CreativeWorkSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_publishing_components/presenters/machine_readable/creative_work_schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ CreativeWorkSchema

Returns a new instance of CreativeWorkSchema.



6
7
8
9
# File 'lib/govuk_publishing_components/presenters/machine_readable/creative_work_schema.rb', line 6

def initialize(page)
  @page = page
  @pages = {}
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



4
5
6
# File 'lib/govuk_publishing_components/presenters/machine_readable/creative_work_schema.rb', line 4

def page
  @page
end

Instance Method Details

#structured_dataObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/govuk_publishing_components/presenters/machine_readable/creative_work_schema.rb', line 11

def structured_data
  # http://schema.org/CreativeWork
  {
    "@context" => "http://schema.org",
    "@type" => "CreativeWork",
    "mainEntityOfPage" => {
      "@type" => "WebPage",
      "@id" => page.canonical_url,
    },
    "name" => page.title,
    "datePublished" => page.content_item["first_published_at"],
    "dateModified" => page.content_item["public_updated_at"],
    "text" => page.description,
    "publisher" => {
      "@type" => "Organization",
      "name" => "GOV.UK",
      "url" => "https://www.gov.uk",
      "logo" => {
        "@type" => "ImageObject",
        "url" => page.logo_url,
      },
    },
  }.merge(image_schema).merge(author_schema).merge(is_part_of).merge(about).merge(has_part)
end