Class: GovukPublishingComponents::Presenters::AttachmentHelper::SupportedContentType
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::AttachmentHelper::SupportedContentType
- Defined in:
- lib/govuk_publishing_components/presenters/attachment_helper.rb
Constant Summary collapse
- TYPES =
[ { content_type: "application/msword", name: "MS Word Document", document: true }.freeze, # doc { content_type: "application/pdf", abbr: "PDF", name: "Portable Document Format", document: true }.freeze, { content_type: "application/postscript", extension: ".ps", abbr: "PS", name: "PostScript" }.freeze, { content_type: "application/postscript", extension: ".eps", abbr: "EPS", name: "Encapsulated PostScript" }.freeze, { content_type: "application/rtf", abbr: "RTF", name: "Rich Text Format" }.freeze, { content_type: "application/vnd.ms-excel", name: "MS Excel Spreadsheet", spreadsheet: true }.freeze, { content_type: "application/vnd.ms-excel.sheet.macroenabled.12", abbr: "XLSM", name: "MS Excel Macro-Enabled Workbook" }.freeze, { content_type: "application/vnd.ms-powerpoint", name: "MS PowerPoint Presentation" }.freeze, # ppt { content_type: "application/vnd.oasis.opendocument.presentation", abbr: "ODP", name: "OpenDocument Presentation", opendocument: true }.freeze, { content_type: "application/vnd.oasis.opendocument.spreadsheet", abbr: "ODS", name: "OpenDocument Spreadsheet", opendocument: true, spreadsheet: true }.freeze, { content_type: "application/vnd.oasis.opendocument.text", abbr: "ODT", name: "OpenDocument Text document", opendocument: true, document: true }.freeze, { content_type: "application/vnd.openxmlformats-officedocument.presentationml.presentation", name: "MS PowerPoint Presentation" }.freeze, # pptx { content_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", name: "MS Excel Spreadsheet", spreadsheet: true }.freeze, # xlsx { content_type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", name: "MS Word Document", document: true }.freeze, # docx { content_type: "application/zip", abbr: "ZIP", name: "Zip archive" }.freeze, { content_type: "application/xml", abbr: "XML", name: "XML Document" }.freeze, { content_type: "image/gif", abbr: "GIF", name: "Graphics Interchange Format" }.freeze, { content_type: "image/jpeg", name: "JPEG" }.freeze, { content_type: "image/png", abbr: "PNG", name: "Portable Network Graphic" }.freeze, { content_type: "image/vnd.dxf", abbr: "DXF", name: "AutoCAD Drawing Exchange Format" }.freeze, { content_type: "text/csv", abbr: "CSV", name: "Comma-separated Values", spreadsheet: true }.freeze, { content_type: "text/plain", name: "Plain Text" }.freeze, { content_type: "text/xml", extension: ".xml", abbr: "XML", name: "XML Document" }.freeze, { content_type: "text/xml", extension: ".xsd", abbr: "XSD", name: "XML Schema" }.freeze, ].freeze
Instance Attribute Summary collapse
-
#content_type_data ⇒ Object
readonly
Returns the value of attribute content_type_data.
Class Method Summary collapse
Instance Method Summary collapse
- #abbr ⇒ Object
- #content_type ⇒ Object
- #document? ⇒ Boolean
-
#initialize(content_type_data) ⇒ SupportedContentType
constructor
A new instance of SupportedContentType.
- #name ⇒ Object
- #opendocument? ⇒ Boolean
- #spreadsheet? ⇒ Boolean
Constructor Details
#initialize(content_type_data) ⇒ SupportedContentType
Returns a new instance of SupportedContentType.
134 135 136 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 134 def initialize(content_type_data) @content_type_data = content_type_data end |
Instance Attribute Details
#content_type_data ⇒ Object (readonly)
Returns the value of attribute content_type_data.
91 92 93 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 91 def content_type_data @content_type_data end |
Class Method Details
.find(content_type, extension = nil) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 120 def self.find(content_type, extension = nil) matching_types = TYPES.select { |type| type[:content_type] == content_type } return UnsupportedContentType.new(content_type:) if matching_types.empty? extension_match = if matching_types.length > 1 matching_types.find { |type| type[:extension] == extension } end content_type = extension_match || matching_types.first new(content_type) end |
Instance Method Details
#abbr ⇒ Object
142 143 144 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 142 def abbr content_type_data[:abbr] end |
#content_type ⇒ Object
138 139 140 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 138 def content_type content_type_data[:content_type] end |
#document? ⇒ Boolean
154 155 156 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 154 def document? content_type_data[:document].present? end |
#name ⇒ Object
146 147 148 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 146 def name content_type_data[:name] end |
#opendocument? ⇒ Boolean
150 151 152 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 150 def opendocument? content_type_data[:opendocument].present? end |
#spreadsheet? ⇒ Boolean
158 159 160 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 158 def spreadsheet? content_type_data[:spreadsheet].present? end |