Class: GovukPublishingComponents::Presenters::DevolvedNationsHelper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local_assigns) ⇒ DevolvedNationsHelper

Returns a new instance of DevolvedNationsHelper.



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

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

Instance Attribute Details

#national_applicabilityObject (readonly)

Returns the value of attribute national_applicability.



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

def national_applicability
  @national_applicability
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#alternative_content_text(name) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/govuk_publishing_components/presenters/devolved_nations_helper.rb', line 30

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

#applicable_nations_title_textObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/govuk_publishing_components/presenters/devolved_nations_helper.rb', line 11

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

#nations_with_urlsObject



22
23
24
25
26
27
28
# File 'lib/govuk_publishing_components/presenters/devolved_nations_helper.rb', line 22

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