Sha256: 59d2132a7bb22d6c8afa4f188213f6cbb80446e34cfd7d2649da30a2102b112b

Contents?: true

Size: 1.49 KB

Versions: 42

Compression:

Stored size: 1.49 KB

Contents

module GovukPublishingComponents
  module Presenters
    class GovernmentServiceSchema
      attr_reader :page

      def initialize(page)
        @page = page
      end

      def structured_data
        # http://schema.org/GovernmentService
        {
          "@context" => "http://schema.org",
          "@type" => "GovernmentService",
          "name" => page.title,
          "description" => page.description,
          "url" => page.canonical_url
        }
          .merge(provider)
          .merge(related_services)
      end

    private

      def related_services
        related_links = page.content_item.dig('links', 'ordered_related_items')

        return {} unless related_links.present?

        {
          "isRelatedTo" => related_links.each_with_object([]) do |link, items|
            if link['schema_name'] == 'transaction'
              items << {
                "@type" => "GovernmentService",
                "name" => link['title'],
                "url" => link['web_url']
              }
            end
          end
        }
      end

      def provider
        organisations = page.content_item.dig('links', 'organisations')

        return {} unless organisations.present?

        providers = organisations.map do |organisation|
          {
            "@type" => "GovernmentOrganization",
            "name" => organisation['title'],
            "url" => organisation['web_url']
          }
        end

        {
          "provider" => providers
        }
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
govuk_publishing_components-21.17.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.16.3 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.16.2 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.16.1 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.16.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.15.2 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.15.1 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.15.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.14.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.13.5 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.13.4 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.13.3 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.13.2 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.13.1 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.13.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.12.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.11.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.10.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.9.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.8.1 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb