Class: ContentBlockTools::Presenters::BlockPresenters::Contact::TelephonePresenter

Inherits:
BasePresenter
  • Object
show all
Includes:
BlockLevelContactItem
Defined in:
lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb

Constant Summary

Constants included from BlockLevelContactItem

BlockLevelContactItem::BASE_TAG_TYPE

Constants inherited from BasePresenter

BasePresenter::BASE_TAG_TYPE

Instance Attribute Summary

Attributes inherited from BasePresenter

#item

Instance Method Summary collapse

Methods included from BlockLevelContactItem

#initialize, #title, #wrapper

Methods inherited from BasePresenter

#initialize

Methods included from Govspeak

#render_govspeak

Instance Method Details



69
70
71
72
73
74
75
76
77
78
# File 'lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb', line 69

def call_charges_link
  if item[:show_uk_call_charges] == "true"
    (:p) do
      concat (:a,
                         "Find out about call charges",
                         class: "govuk-link",
                         href: "https://www.gov.uk/call-charges")
    end
  end
end

#descriptionObject



38
39
40
# File 'lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb', line 38

def description
  render_govspeak(item[:description], root_class: "govuk-!-margin-top-1 govuk-!-margin-bottom-0")
end

#item_titleObject



34
35
36
# File 'lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb', line 34

def item_title
  (:p, item[:title], { class: "govuk-!-margin-bottom-0" })
end

#number_listObject



42
43
44
45
46
47
48
# File 'lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb', line 42

def number_list
  (:ul) do
    item[:telephone_numbers].each do |number|
      concat number_list_item(number)
    end
  end
end

#number_list_item(number) ⇒ Object



50
51
52
53
54
55
# File 'lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb', line 50

def number_list_item(number)
  (:li) do
    concat (:span, number[:label])
    concat (:span, number[:telephone_number], { class: "tel" })
  end
end

#opening_hours_listObject



57
58
59
60
61
62
63
# File 'lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb', line 57

def opening_hours_list
  (:ul) do
    item[:opening_hours].each do |item|
      concat opening_hours_list_item(item)
    end
  end
end

#opening_hours_list_item(item) ⇒ Object



65
66
67
# File 'lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb', line 65

def opening_hours_list_item(item)
  (:li, "#{item[:day_from]} to #{item[:day_to]}, #{item[:time_from]} to #{item[:time_to]}")
end

#renderObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb', line 10

def render
  wrapper do
    (:div, class: "email-url-number") do
      concat title_and_description
      concat number_list
      concat opening_hours_list if item[:opening_hours].present?
      concat call_charges_link
    end
  end
end

#title_and_descriptionObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb', line 21

def title_and_description
  items = [
    (item_title if item[:title].present?),
    (description if item[:description].present?),
  ].compact

  if items.any?
    (:div, class: "govuk-!-margin-bottom-3") do
      concat items.join("").html_safe
    end
  end
end