Module: Vpim::Attachment
- Defined in:
- lib/vpim/attachment.rb
Overview
Attachments are used by both iCalendar and vCard. They are either a URI or inline data, and their decoded value will be either a Uri or a Inline, as appropriate.
Besides the methods specific to their class, both kinds of object implement a set of common methods, allowing them to be treated uniformly:
-
Uri#to_io, Inline#to_io: return an IO from which the value can be read.
-
Uri#to_s, Inline#to_s: return the value as a String.
-
Uri#format, Inline#format: the format of the value. This is supposed to be an “iana defined” identifier (like “image/jpeg”), but could be almost anything (or nothing) in practice. Since the parameter is optional, it may be “”.
The objects can also be distinguished by their class, if necessary.
Defined Under Namespace
Class Method Summary collapse
-
.decode(field, defkind, fmtparam) ⇒ Object
TODO - It might be possible to autodetect the format from the first few bytes of the value, and return the appropriate MIME type when format isn’t defined.
Class Method Details
.decode(field, defkind, fmtparam) ⇒ Object
TODO - It might be possible to autodetect the format from the first few bytes of the value, and return the appropriate MIME type when format isn’t defined.
iCalendar and vCard put the format in different parameters, and the default kind of value is different.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vpim/attachment.rb', line 35 def Attachment.decode(field, defkind, fmtparam) #:nodoc: format = field.pvalue(fmtparam) || '' kind = field.kind || defkind case kind when 'text' Inline.new(Vpim.decode_text(field.value), format) when 'uri' Uri.new(field.value_raw, format) when 'binary' Inline.new(field.value, format) else raise InvalidEncodingError, "Attachment of type #{kind} is not allowed" end end |