Class: GovukPublishingComponents::Presenters::AttachmentHelper
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::AttachmentHelper
show all
- Defined in:
- lib/govuk_publishing_components/presenters/attachment_helper.rb
Defined Under Namespace
Classes: SupportedContentType, UnsupportedContentType
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Expects a hash of attachment data
-
title and url are required
-
type, content_type, filename, file_size, number of pages, alternative_format_contact_email can be provided
11
12
13
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 11
def initialize(attachment_data)
@attachment_data = attachment_data.with_indifferent_access
end
|
Instance Attribute Details
#attachment_data ⇒ Object
Returns the value of attribute attachment_data.
6
7
8
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 6
def attachment_data
@attachment_data
end
|
Instance Method Details
62
63
64
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 62
def alternative_format_contact_email
attachment_data[:alternative_format_contact_email]
end
|
#content_type ⇒ Object
39
40
41
42
43
44
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 39
def content_type
@content_type ||= SupportedContentType.find(
attachment_data[:content_type],
attachment_data[:filename] ? File.extname(attachment_data[:filename]) : nil,
)
end
|
#content_type_abbr ⇒ Object
46
47
48
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 46
def content_type_abbr
content_type.abbr
end
|
#content_type_name ⇒ Object
50
51
52
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 50
def content_type_name
content_type.name
end
|
#file_size ⇒ Object
54
55
56
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 54
def file_size
attachment_data[:file_size]
end
|
#html? ⇒ Boolean
35
36
37
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 35
def html?
type == "html"
end
|
#is_official_document ⇒ Object
86
87
88
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 86
def is_official_document
attachment_data[:command_paper_number].present? || attachment_data[:hoc_paper_number].present? || attachment_data[:unnumbered_command_paper].eql?(true) || attachment_data[:unnumbered_hoc_paper].eql?(true)
end
|
#number_of_pages ⇒ Object
58
59
60
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 58
def number_of_pages
attachment_data[:number_of_pages]
end
|
#preview_url ⇒ Object
19
20
21
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 19
def preview_url
@attachment_data[:preview_url]
end
|
#reference ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 66
def reference
reference = []
reference << "ISBN #{attachment_data[:isbn]}" if attachment_data[:isbn].present?
reference << attachment_data[:unique_reference] if attachment_data[:unique_reference].present?
reference << attachment_data[:command_paper_number] if attachment_data[:command_paper_number].present?
if attachment_data[:hoc_paper_number].present?
hoc_reference = "HC #{attachment_data[:hoc_paper_number]}"
hoc_reference += " #{attachment_data[:parliamentary_session]}" if attachment_data[:parliamentary_session].present?
reference << hoc_reference
end
reference.join(", ")
end
|
#thumbnail_url ⇒ Object
15
16
17
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 15
def thumbnail_url
@attachment_data[:thumbnail_url]
end
|
#title ⇒ Object
23
24
25
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 23
def title
attachment_data.fetch(:title)
end
|
#type ⇒ Object
31
32
33
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 31
def type
attachment_data.fetch(:type, "file")
end
|
#unnumbered_reference ⇒ Object
80
81
82
83
84
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 80
def unnumbered_reference
unnumbered_reference = "Unnumbered command paper" if attachment_data[:unnumbered_command_paper].eql?(true) && attachment_data[:command_paper_number].blank?
unnumbered_reference = "Unnumbered act paper" if attachment_data[:unnumbered_hoc_paper].eql?(true) && attachment_data[:hoc_paper_number].blank?
unnumbered_reference
end
|
#url ⇒ Object
27
28
29
|
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 27
def url
attachment_data.fetch(:url)
end
|