Class: SMail::MIME::ContentType
- Inherits:
-
ContentField
- Object
- ContentField
- SMail::MIME::ContentType
- Defined in:
- lib/smail/mime/content_fields.rb
Overview
ContentDisposition
Instance Attribute Summary collapse
-
#media_subtype_raw ⇒ Object
Returns the value of attribute media_subtype_raw.
-
#media_type_raw ⇒ Object
Returns the value of attribute media_type_raw.
Attributes inherited from ContentField
Instance Method Summary collapse
-
#composite? ⇒ Boolean
Is this a composite media type as specified in section 5.1 of RFC 2045.
-
#discrete? ⇒ Boolean
Is this a discrete media type as specified in section 5.1 of RFC 2045.
-
#initialize(text = nil) ⇒ ContentType
constructor
A new instance of ContentType.
-
#media_subtype ⇒ Object
Returns the media subtype.
-
#media_subtype=(text) ⇒ Object
Set the media subtype.
-
#media_type ⇒ Object
Returns the media type.
-
#media_type=(text) ⇒ Object
Set the media type.
-
#to_s ⇒ Object
Returns the full Content-Type header as a string suitable for inclusion in an email header.
-
#type ⇒ Object
Returns the media ‘type/subtype’ as a lower case string.
-
#type=(text = nil) ⇒ Object
Set the media ‘type/subtype’ together.
Constructor Details
#initialize(text = nil) ⇒ ContentType
Returns a new instance of ContentType.
117 118 119 120 |
# File 'lib/smail/mime/content_fields.rb', line 117 def initialize(text = nil) super(text) self.type = @type_raw end |
Instance Attribute Details
#media_subtype_raw ⇒ Object
Returns the value of attribute media_subtype_raw.
115 116 117 |
# File 'lib/smail/mime/content_fields.rb', line 115 def media_subtype_raw @media_subtype_raw end |
#media_type_raw ⇒ Object
Returns the value of attribute media_type_raw.
115 116 117 |
# File 'lib/smail/mime/content_fields.rb', line 115 def media_type_raw @media_type_raw end |
Instance Method Details
#composite? ⇒ Boolean
Is this a composite media type as specified in section 5.1 of RFC 2045.
Note extension tokens are permitted to be composite but will always be seen as discrete by this code.
164 165 166 |
# File 'lib/smail/mime/content_fields.rb', line 164 def composite? media_type == 'message' or media_type == 'multipart' end |
#discrete? ⇒ Boolean
Is this a discrete media type as specified in section 5.1 of RFC 2045.
Note extension tokens are permitted to be composite but will always be seen as discrete by this code.
172 173 174 |
# File 'lib/smail/mime/content_fields.rb', line 172 def discrete? !composite? end |
#media_subtype ⇒ Object
Returns the media subtype
133 134 135 |
# File 'lib/smail/mime/content_fields.rb', line 133 def media_subtype @media_subtype.nil? ? @media_subtype_raw : @media_subtype_raw.downcase end |
#media_subtype=(text) ⇒ Object
Set the media subtype
138 139 140 |
# File 'lib/smail/mime/content_fields.rb', line 138 def media_subtype=(text) @media_subtype_raw = text end |
#media_type ⇒ Object
Returns the media type
123 124 125 |
# File 'lib/smail/mime/content_fields.rb', line 123 def media_type @media_type_raw.nil? ? @media_type_raw : @media_type_raw.downcase end |
#media_type=(text) ⇒ Object
Set the media type
128 129 130 |
# File 'lib/smail/mime/content_fields.rb', line 128 def media_type=(text) @media_type_raw = text end |
#to_s ⇒ Object
Returns the full Content-Type header as a string suitable for inclusion in an email header. If either of the media type or subtype are not specified it will default to ‘text/plain; charset=us-ascii’.
179 180 181 182 183 184 185 186 |
# File 'lib/smail/mime/content_fields.rb', line 179 def to_s # Default to 'text/plain; charset=us-ascii' if @media_type_raw.nil? or @media_subtype_raw.nil? 'text/plain; charset=us-ascii' else "#{@media_type_raw}/#{@media_subtype_raw}#{self.params.to_s}" end end |
#type ⇒ Object
Returns the media ‘type/subtype’ as a lower case string.
143 144 145 146 147 148 149 150 |
# File 'lib/smail/mime/content_fields.rb', line 143 def type # Default to 'text/plain' if @media_type_raw.nil? or @media_subtype_raw.nil? 'text/plain' else "#{@media_type_raw}/#{@media_subtype_raw}".downcase end end |
#type=(text = nil) ⇒ Object
Set the media ‘type/subtype’ together
153 154 155 156 157 158 |
# File 'lib/smail/mime/content_fields.rb', line 153 def type=(text = nil) unless text.nil? @type_raw = text # keep this inherited accessor in sync (@media_type_raw, @media_subtype_raw) = text.split('/', 2) end end |