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/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.
117 118 119 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 117 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.
75 76 77 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 75 def content_type_data @content_type_data end |
Class Method Details
.find(content_type, extension = nil) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 103 def self.find(content_type, extension = nil) matching_types = TYPES.select { |type| type[:content_type] == content_type } return UnsupportedContentType.new(content_type: 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
125 126 127 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 125 def abbr content_type_data[:abbr] end |
#content_type ⇒ Object
121 122 123 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 121 def content_type content_type_data[:content_type] end |
#document? ⇒ Boolean
137 138 139 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 137 def document? content_type_data[:document].present? end |
#name ⇒ Object
129 130 131 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 129 def name content_type_data[:name] end |
#opendocument? ⇒ Boolean
133 134 135 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 133 def opendocument? content_type_data[:opendocument].present? end |
#spreadsheet? ⇒ Boolean
141 142 143 |
# File 'lib/govuk_publishing_components/presenters/attachment_helper.rb', line 141 def spreadsheet? content_type_data[:spreadsheet].present? end |