Sha256: e481ed77a3f79db52e26ad709eff6fad0aa5fa6aebf4539965d75cadfb37cbab

Contents?: true

Size: 1.27 KB

Versions: 132

Compression:

Stored size: 1.27 KB

Contents

module GovukPublishingComponents
  module Presenters
    class DevolvedNationsHelper
      attr_reader :national_applicability, :type

      def initialize(local_assigns)
        @national_applicability = local_assigns[:national_applicability]
        @type = local_assigns[:type] || "publication"
      end

      def applicable_nations_title_text
        @national_applicability
          .select { |_, v| v[:applicable] == true }
          .map { |k, _| I18n.t("components.devolved_nations.#{k}") }
          .sort
          .to_sentence(
            two_words_connector: I18n.t("components.devolved_nations.connectors.two_words"),
            last_word_connector: I18n.t("components.devolved_nations.connectors.last_word"),
          )
      end

      def nations_with_urls
        @national_applicability
          .select do |_, v|
            v[:alternative_url]
            .present?
          end
      end

      def alternative_content_text(name)
        nation = I18n.t("components.devolved_nations.#{name}")

        if I18n.exists?("components.devolved_nations.type.#{@type}")
          I18n.t("components.devolved_nations.type.#{@type}", nation: nation)
        else
          I18n.t("components.devolved_nations.type.publication", nation: nation)
        end
      end
    end
  end
end

Version data entries

132 entries across 132 versions & 1 rubygems

Version Path
govuk_publishing_components-35.14.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.13.2 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.13.1 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.13.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.12.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.11.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.10.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.9.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.8.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.7.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.6.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.5.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.4.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.3.5 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.3.4 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.3.3 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.3.2 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.3.1 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.3.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-35.2.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb