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



42
43
44
45
46
47
48
49
50
# File 'lib/govuk_publishing_components/presenters/devolved_nations_helper.rb', line 42

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:)
  else
    I18n.t("components.devolved_nations.type.publication", nation:)
  end
end

#applicable_nations_title_text(use_english_translation = nil) ⇒ Object



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(use_english_translation = nil)
  @national_applicability
    .select { |_, v| v[:applicable] == true }
    .map { |k, _| get_translation("components.devolved_nations.#{k}", use_english_translation) }
    .sort
    .to_sentence(
      two_words_connector: get_translation("components.devolved_nations.connectors.two_words", use_english_translation),
      last_word_connector: get_translation("components.devolved_nations.connectors.last_word", use_english_translation),
    )
end

#ga4_applicable_nations_title_text(remove_connector_word = nil) ⇒ Object



28
29
30
31
32
# File 'lib/govuk_publishing_components/presenters/devolved_nations_helper.rb', line 28

def ga4_applicable_nations_title_text(remove_connector_word = nil)
  return applicable_nations_title_text(true).gsub(" and", ",") if remove_connector_word

  applicable_nations_title_text(true)
end

#get_translation(key, use_english_translation = nil) ⇒ Object



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

def get_translation(key, use_english_translation = nil)
  return I18n.t(key, locale: :en) if use_english_translation

  I18n.t(key)
end

#nations_with_urlsObject



34
35
36
37
38
39
40
# File 'lib/govuk_publishing_components/presenters/devolved_nations_helper.rb', line 34

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