class GovukPublishingComponents::Presenters::Attachment

Attributes

attachment_data[R]

Public Class Methods

new(attachment_data) click to toggle source

Expects a hash of attachment data

# File lib/govuk_publishing_components/presenters/attachment.rb, line 11
def initialize(attachment_data)
  @attachment_data = attachment_data.with_indifferent_access
end

Public Instance Methods

alternative_format_contact_email() click to toggle source
# File lib/govuk_publishing_components/presenters/attachment.rb, line 46
def alternative_format_contact_email
  attachment_data[:alternative_format_contact_email]
end
content_type() click to toggle source
# File lib/govuk_publishing_components/presenters/attachment.rb, line 23
def content_type
  @content_type ||= SupportedContentType.find(
    attachment_data[:content_type],
    attachment_data[:filename] ? File.extname(attachment_data[:filename]) : nil,
  )
end
content_type_abbr() click to toggle source
# File lib/govuk_publishing_components/presenters/attachment.rb, line 30
def content_type_abbr
  content_type.abbr
end
content_type_name() click to toggle source
# File lib/govuk_publishing_components/presenters/attachment.rb, line 34
def content_type_name
  content_type.name
end
file_size() click to toggle source
# File lib/govuk_publishing_components/presenters/attachment.rb, line 38
def file_size
  attachment_data[:file_size]
end
is_official_document() click to toggle source
# File lib/govuk_publishing_components/presenters/attachment.rb, line 70
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() click to toggle source
# File lib/govuk_publishing_components/presenters/attachment.rb, line 42
def number_of_pages
  attachment_data[:number_of_pages]
end
reference() click to toggle source
# File lib/govuk_publishing_components/presenters/attachment.rb, line 50
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
title() click to toggle source
# File lib/govuk_publishing_components/presenters/attachment.rb, line 15
def title
  attachment_data.fetch(:title)
end
unnumbered_reference() click to toggle source
# File lib/govuk_publishing_components/presenters/attachment.rb, line 64
def unnumbered_reference
  unnumbered_reference = "Unnumbered command paper" if attachment_data[:unnumbered_command_paper].eql?(true) && !attachment_data[:command_paper_number]
  unnumbered_reference = "Unnumbered act paper" if attachment_data[:unnumbered_hoc_paper].eql?(true) && !attachment_data[:hoc_paper_number]
  unnumbered_reference
end
url() click to toggle source
# File lib/govuk_publishing_components/presenters/attachment.rb, line 19
def url
  attachment_data.fetch(:url)
end