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.27.1 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.27.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.26.2 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.26.1 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.26.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.25.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.24.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.23.1 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.23.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.22.2 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.22.1 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.22.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.21.3 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.21.2 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.21.1 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.21.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.20.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.19.1 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.19.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb
govuk_publishing_components-21.18.0 lib/govuk_publishing_components/presenters/machine_readable/government_service_schema.rb